java - Issues in onBackpressed() -


actually issue when press button shows dialog , @ same time application finished without operation on key? can 1 solve this?

@override public void onbackpressed() {     super.onbackpressed();     alertdialog.builder ab = new alertdialog.builder(this);     ab.setmessage("really want exit");     ab.setpositivebutton("yes", new dialoginterface.onclicklistener() {         @override         public void onclick(dialoginterface dialog, int which) {             finish();         }     });     ab.setnegativebutton("no", new dialoginterface.onclicklistener() {         @override         public void onclick(dialoginterface dialog, int which) {             main.super.onbackpressed();         }     });     ab.create();     ab.show(); } 

remove super.onbackpressed(); method, keep in onclick() only

@override public void onbackpressed() {     super.onbackpressed(); //remove  } 

seems performing same operation in both buttons, should remove main.super.onbackpressed() negativebutton

ab.setpositivebutton("yes", new dialoginterface.onclicklistener() {     @override     public void onclick(dialoginterface dialog, int which) {         super.onbackpressed();     } }); ab.setnegativebutton("no", new dialoginterface.onclicklistener() {     @override     public void onclick(dialoginterface dialog, int which) {         ab.dismiss();     } }); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -