Exit app on second back button click - Android -
i have log in screen , on log in screen if press button once nothing happens if press second time app stops/exits, have seen other questions on here me non of solutions work ...
any appreciated thank you!
this attempt of mine doesnt exit on second press restarts app , when click twice again exits ... ;
@override public void onbackpressed() { if (doublebacktoexitpressedonce) { super.onbackpressed(); return; } this.doublebacktoexitpressedonce = true; toast.maketext(this, "please click again exit", toast.length_short).show(); new handler().postdelayed(new runnable() { @override public void run() { doublebacktoexitpressedonce=false; } }, 2000); }
try one:
private static long saybackpress; @override public void onbackpressed() { if (saybackpress + 2000 > system.currenttimemillis()){ super.onbackpressed(); } else{ toast.maketext(mainactivity.this, "press once again exit!", toast.length_short).show(); saybackpress = system.currenttimemillis(); } }
Comments
Post a Comment