how to show confirmation dialogue box on mobile back button in android app? -


i want set confirmation dialogue box when user press button of mobile. there should asked user "do want exit?".

add code:

@override public boolean onkeydown(int keycode, keyevent event) {     if (keycode == keyevent.keycode_back) {         showdialog();     }     return super.onkeydown(keycode, event); } 

then add below:

public void showpausedialog() {      new alertdialog.builder(exerciseactivity.this)             .settitle("are sure want exit?")             .setpositivebutton("yes", new dialoginterface.onclicklistener() {                 public void onclick(dialoginterface dialog, int which) {                     //leave activity                     this.finish();                 }             })             .setnegativebutton("no", new dialoginterface.onclicklistener() {                 public void onclick(dialoginterface dialog, int which) {                     //do nothing                 }             })             .seticon(android.r.drawable.ic_dialog_alert)             .show(); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -