Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Chintan Rathod ChintanRathod

🎯
Focusing
View GitHub Profile
@ChintanRathod
ChintanRathod / DoubleBackPressExit
Created Apr 8, 2015
To prevent user exit from activity with single "back" press, following short of code will ask to press another time "back" button to exit.
View DoubleBackPressExit
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press once again to exit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
You can’t perform that action at this time.