@Override
public void onCreate(Bundle savedInstanceState) {
mContext = getApplicationContext();
super.onCreate(savedInstanceState);
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
return;
}
// your current codes
// your current codes
}
@Override
public void onBackPressed(){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
}
public void yourFunction()
{
finishAffinity();
moveTaskToBack(true);
}
//For an instance, if you want to exit an application on double click of a
//button,then the following code can be used.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 2) {
// do something on back.
From Android 16+ you can use the following:
finishAffinity();
moveTaskToBack(true);
}
return super.onKeyDown(keyCode, event);
}