android onBackPressed method in fragment need help for exit from application -


I'm using piece in an application. Now I want to add the AlertBob to the back key press but I In the expanded category, the backdrop () method is not able to get public naught on. How can I achieve this? My main activity increases the piece activity.

  backdone at public zero (super.onBackpressed (); Alertbox ("myappname", "Do you want to exit?"); }   

But it does not display a dialog, or if it shows that it disappears in 1 second. What am i doing wrong

Use it to exit

Code

  Override public boolean on KeyDown (int keycode, KeyEvent event) {if ((keycode == KeyEvent.KEYCODE_BACK)) {AlertDialog.Builder alertbox = New AlertDialog Builder (main activity.); alertbox.setTitle ("Do you want to exit?"); Alertbox.setPositiveButton ("Yes", New DialogInterface.OnClickListener () {click on Public Zero (DialogInterface arg0, int arg1) {// Finish to Deletion End Activity ();}}); Nothing will be done when clicking on Alertbox.setNegativeButton ("No", New DialogInterface.OnClickListener () {Public Zero (DialogInterface arg0, int arg1) // // Click any button of dialog;); Alertbox.show (); } Return super.Condondon (keycode, event); } Public exit from zero () {intention intended = new intent (Intent.ACTION_MAIN); Intent.addCategory (Intent.CATEGORY_HOME); Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); StartActivity; }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -