@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { destory = true; Music.pause(); new AlertDialog.Builder(this) .setTitle("退出游戏") .setMessage("当前退出,游戏以失败结束...") // .setIcon(R.drawable.quit) .setPositiveButton( "放弃", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // System.out.println(handler.sendEmptyMessage(2)); startActivity(new Intent(MatchActivity.this, EndActivity.class)); MatchActivity.this.finish(); } }) .setNegativeButton( "取消", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // 取消按钮事件 destory = false; Music.play(); } }) .show(); } return super.onKeyDown(keyCode, event); }
@Override public void onPause() { // TODO Auto-generated method stub Log.i("tag", "onPause"); super.onPause(); // 暂停音乐 if (Set.isMusic() && (!destory) && music.isPlaying()) { Music.pause(); } // 转到暂停界面 if ((!isPause) && (!destory)) { Intent intent = new Intent(); } }