Double back press to exit

9 votes · 5 comments

Get back press work only at second press and notify user to press again to exit.

raw ·
copy
· download
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(); }
Add a comment

5 Comments

thank you but why do i use double back key press? i can not use single key press for exit? what different between two action?

Reply · Jan. 9, 2014, 2:09 p.m.

Nice and Simple :)

Reply · March 28, 2014, 9:49 a.m.

very nice ;)

Reply · May 21, 2014, 7:58 p.m.

Problem SOLVED. Thank you! :)

Reply · May 29, 2014, 9:59 a.m.

nice. thank you!

Reply · Oct. 22, 2014, 7:49 a.m.