I use below code for my ActionBar
Button
, it can back to previous Activity
and also display the Toast
.
case android.R.id.home:
Toast.makeText(getApplication(),"A",Toast.LENGTH_SHORT).show();
onBackPressed();
return true;
If I press back in my emulator, no Toast display. So I decide to add this
public void onBackPressed()
{
Toast.makeText(getApplication(),"A",Toast.LENGTH_SHORT).show();
return;
}
After added this, when I press the back button in the emulator, it to display Toast
but not returning to previous Activity
. I click the ActionBar
Button
, same thing happened.
Try to run super method :
It will call normal back press, and shows
Toast