1、android的Activity中有个方法,用于处理返回键,如果我们需要处理返回键的拿下, 只需要重写这个方法就可了。
/**
* Called when the activity has detected the user's press of the back
* key. The default implementation simply finishes the current activity,
* but you can override this to do whatever you want.
*/
public void onBackPressed() {
if (!mFragments.popBackStackImmediate()) {
finish();
}
}
2、我们的public class AndroidLauncher 本身就是继承自Activity,所以我们在这里重写这个方法就可以。
3、退出对话框:
AndroidLauncher.getInstance().runOnUiThread(new Runnable() { //这里必须要有
@Override
public void run() {
new AlertDialog.Builder(AndroidLauncher.getInstance())
.setTitle(R.string.exit_tip)
.setMessage(R.string.exit_message)
.setNegativeButton(R.string.exit_cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
})
.setPositiveButton(R.string.exit_confirm,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
Game.app.exit();
}
}).show();
}
});