Skip to content

Instantly share code, notes, and snippets.

@ibrahim-mrq
Created November 24, 2022 08:40
Show Gist options
  • Select an option

  • Save ibrahim-mrq/471d8fccc2ecde3d4510b76d6b520c65 to your computer and use it in GitHub Desktop.

Select an option

Save ibrahim-mrq/471d8fccc2ecde3d4510b76d6b520c65 to your computer and use it in GitHub Desktop.
private android.widget.Toast backToasty;
private long backPressedTime;
@Override
public void onBackPressed() {
if (backPressedTime + 2000 > System.currentTimeMillis()) {
backToasty.cancel();
super.onBackPressed();
return;
} else {
backToasty = android.widget.Toast.makeText($context$, "Press back again to exit.", Toast.LENGTH_SHORT);
backToasty.show();
}
backPressedTime = System.currentTimeMillis();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment