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;
} …Run Code Online (Sandbox Code Playgroud) android ×1