Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreateOptionsMenu(Menu menu) only gets called once during the lifecycle of an Activity

Tags:

android

I noticed that

@Override
public boolean onCreateOptionsMenu(Menu menu) {

only gets called once. I need this to get called every time the menu is displayed because I add/remove items from the menu depending on the application state.

is this possible?

like image 961
jax Avatar asked Dec 12 '10 03:12

jax


Video Answer


1 Answers

Yes. To do that you need to use:

public boolean onPrepareOptionsMenu (Menu menu) 

That code will be executed every time before your options menu is shown. More information here.

like image 85
Luis Miguel Serrano Avatar answered Oct 21 '22 03:10

Luis Miguel Serrano