What does onPrepareOptionsMenu do?

Tutompita picture Tutompita · May 26, 2013 · Viewed 43.1k times · Source

I want to make Option Menu for Android, I have visit this site. In their script, I found onPrepareOptionsMenu, I try to compile and run using Android 2.3.3 compiler with and without onPrepareOptionsMenu, both works, but I didn't see any difference.

public boolean onCreateOptionsMenu(Menu menu){
    //code here
}
    
public boolean onOptionsItemSelected(MenuItem item){
    //code here
}
    
public boolean onPrepareOptionsMenu(Menu menu){
    //code here
}

What is actually onPrepareOptionsMenu method do? Is that method important? Could I just delete the method?


Addition

Oh, I also hear about Action Bar in Android 3.0, it says that Action Bar is the alternative way for make Option Menu, and it using onPrepareOptionsMenu. Is that right?

Thank you...

Answer

Silox picture Silox · May 26, 2013

Take a look in the API:

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.