【发布时间】:2011-10-01 04:44:34
【问题描述】:
Android 上是否存在任何全局活动,例如我将代码放入该活动中,并且它会影响我项目中的所有活动?这发生在我身上,因为相同的代码是在多个活动中编写的,例如KeyEvent.KEYCODE_BACK
例如我在这里使用:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
try {
final Intent itnt_BackServices = new Intent(this,
BackServices.class);
AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
alertbox.setTitle("Touch signs");
alertbox.setMessage("Do you want to quit!");
alertbox.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
stopService(itnt_BackServices);
mPlayer.stop();
finish();
}
});
alertbox.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
alertbox.show();
} catch (Exception e) {
// TODO: handle exception
}
}
return false;
}
我将其复制并粘贴到每个活动中,我宁愿使用某种全局活动。
【问题讨论】:
-
如果您的应用不是游戏,请确认退出对用户体验不利
标签: android