I'm trying to exit my application when the user double taps the HardWare Back Button, I've used the following code in my application:
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
Dashboard_Activity.this.finish();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Please click BACK again to exit",
Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
Here when the user Double Taps the Hardware Back Button the same activity appears again and again, but the app doesn't exits. Can you please help me fixing the issue.