I want the users of my android app to leave my app when they press back at a certain activity. Can this be done?
A good way is to wait for a second back
private boolean _doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
Log.i(TAG, "onBackPressed--");
if (_doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this._doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press again to quit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
_doubleBackToExitPressedOnce = false;
}
}, 2000);
}