android - how to prevent navigation to previous screen and show exit confirm message on back button tap -
i creating quiz app in witch: when use choose answer user navigate next screen.
what want begins here:
i want prevent user go previous screen,
if user try go previous screen taping button, exit confirm message should appear.
if user choose "ok" app should close , if user choose "cancel / (continue quiz)" app should continue current screen.
you need override in activity onbackpressed in way
@override public void onbackpressed() { alertdialog dlg = new alertdialog.builder(youractivity.this).create(); dlg.setcancelable(false); dlg.settitle("close"); dlg.setmessage("are sure?"); dlg.setbutton(dialoginterface.button_negative, "cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { dialog.cancel(); } }); dlg.setbutton(dialoginterface.button_positive, "close app", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { youractivity.super.onbackpressed(); } }); dlg.show(); }
Comments
Post a Comment