Android Overriding onBackPressed() Android Overriding onBackPressed() android android

Android Overriding onBackPressed()


Yes. Only override it in that one Activity with

@Overridepublic void onBackPressed(){     // code here to show dialog     super.onBackPressed();  // optional depending on your needs}

don't 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.


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);    startActivity(intent);    finish();

that worked for me.