求助,新学 android,有个问题,望解答,谢谢
資深大佬 : unixiya 2
如何实现点击返回键,退出一个 while 循环。
public void clickPlay(){ SoundPool mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5); mSoundPool.load(this,R.raw.shuidi,1); int count = 0; while (!result) { keyevent_bool = keyCode != 0; if (keyevent_bool) { break; } try { mSoundPool.play(1, (float) 0.01, (float) 0.01, 0, 0, 1); Thread.sleep(1 * 1000); //设置暂停的时间 1 秒 mSoundPool.stop(1); count++; } catch (InterruptedException e) { e.printStackTrace(); } } mSoundPool.release(); } @Override public void onBackPressed() { super.onBackPressed(); keyCode = KeyEvent.KEYCODE_BACK; }
大佬有話說 (4)