Android Overriding onBackPressed()

Android Overriding onBackPressed()

Yes. Only override it in that one Activity with

public void onBackPressed()
     // code here to show dialog
     super.onBackPressed();  // optional depending on your needs

dont put this code in any other Activity

Override the onBackPressed() method as per the example by codeMagic, and remove the call to super.onBackPressed(); if you do not want the default action (finishing the current activity) to be executed.

Android Overriding onBackPressed()

You may just call the onBackPressed()and if you want some activity to display after the back button you have mention the

Intent intent = new Intent(ResetPinActivity.this, MenuActivity.class);

that worked for me.

Leave a Reply

Your email address will not be published.