AppCompatActivity onBackPressed() method fails to trigger in my activity.
I see the back arrow button and get the animation when pressing it, but nothing else happens. a
I believe onBackPressed()
is only called when the physical back button is pressed. If you're attempting to catch the toolbar back button press (the navigation icon), try using the following snippet:
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home: {
// Your code here
}
}
return (super.onOptionsItemSelected(menuItem));
}