private boolean mDoublePressBackToExit = false;
private boolean mIsBackPressedByTheUser = false;
@Override
public void onBackPressed()
{
if (mDoublePressBackToExit)
{
// process the back button as per normal
mIsBackPressedByTheUser = true;
super.onBackPressed();
return;
}
mDoublePressBackToExit = true; // set flag
Toast.makeText(this, "Press back again to exit...", Toast.LENGTH_SHORT).show();
// reset after time delay
new Handler().postDelayed(
new Runnable() {
@Override
public void run() {
mDoublePressBackToExit = false;
}
}, BACK_PRESS_DELAY
);
}