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.
You can create a class that extends
Activityand then extend theCustomActivityto all theActivityClass like this.Now you can
extendthisclasswhere you want toextendany class withActivity.