Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and how often is the onPrepareOptionsMenu() method called for ActionBar?

It is clear for Activities - the method is being called right before the menu is shown. But what about ActionBar when it is always shown? How to trigger it to be invoked to dynamically update menuItems?

like image 404
Eugene Avatar asked Oct 05 '11 09:10

Eugene


1 Answers

Use invalidateOptionsMenu() to trigger onPrepareOptionMenu() method as suggested by document.

On Android 3.0 and higher, you must call invalidateOptionsMenu() when you want to update the menu, because the menu is always open. The system will then call onPrepareOptionsMenu() so you can update the menu items.

like image 55
PH7 Avatar answered Oct 17 '22 15:10

PH7