Is there any global activity on Android such that I put my code in that one activity, and it affects all activities in my project? This occurs to me because the same code is written in multiple activities like KeyEvent.KEYCODE_BACK
For example here I use:
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;
}
I copy and paste this in each activity, and I would rather use some kind of global activity.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…