I am trying to invoked the onPrepareOptionsMenu()
in the MainActivity after pressing the back button in the Map activity but it is not being invoked after it was created once.
According to the documentation it must be called right before the menu is shown.
Is this case valid after invoking the onBackPressed()?
Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.
Yea you can just add this in your activity. This will make it be called anytime you come back from any activity though.
@Override
public void OnStart()
{
super.onStart();
invalidateOptionsMenu();
}
This is how create and prepare works for menu
onCreateOptionsMenu()
called only once when the Activity or Fragment is created
onPrepareOptionsMenu()
usually used for some dynamic control contents
In order to onPrepareOptionsMenu()
to be triggered you have to call invalidateOptionsMenu()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With