1

I want to show an Alert Dialog when the user clicks on the up button of ActionBar. I have implemented onBackPressed() already. What I want to do now is trigger same action as for pressing Back button when user clicks the Up button from ActionBar.

I tried using onNavigateUp(). However, it just returns me to the parent activity without showing the Alert Dialog.

dkhost07
  • 312
  • 1
  • 4
  • 17

1 Answers1

1

from this answer you can override onOptionsItemSelected to detect action

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
    case android.R.id.home: {
       //enter your code here

        return true;
    }
}
return super.onOptionsItemSelected(item);
}

try it

dkhost07
  • 312
  • 1
  • 4
  • 17
Muhamed El-Banna
  • 593
  • 7
  • 21