Skip to content

Instantly share code, notes, and snippets.

@nisrulz
Created June 21, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisrulz/a9dbb8d0a8c762e5c70961c94a41b370 to your computer and use it in GitHub Desktop.
Save nisrulz/a9dbb8d0a8c762e5c70961c94a41b370 to your computer and use it in GitHub Desktop.
Get back press work only at second press and notify user to press again to exit.
private static long back_pressed;
@Override
public void onBackPressed(){
if (back_pressed + 2000 > System.currentTimeMillis()) super.onBackPressed();
else Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment