Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8598921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:16:23+00:00 2026-06-12T01:16:23+00:00

For some reason, onCreateOptionsMenu() is called AFTER onResume() in my app… Therefore, I just

  • 0

For some reason, onCreateOptionsMenu() is called AFTER onResume() in my app… Therefore, I just can’t get a hold of the menu while I’m setting up my UI (between onCreate() and onResume()), which results in not being able to setup the corresponding action items for my ActionBar…

The only work-around I’ve found so far is to manually call invalidateOptionsMenu() right before onCreate() returns; that way onCreateOptionsMenu() is immediately called, I get a hold of the menu and then I can finally add the desired action items.

Has anyone experienced this issue? How are you supposed to programmatically setup your action items given onCreateOptionsMenu() is called after onResume()?

My app is running on JellyBean, it uses the built-in ActionBar (no ActionBarSherlock), android:minSdkVersion="14" and android:targetSdkVersion="16"

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:16:24+00:00Added an answer on June 12, 2026 at 1:16 am

    First consider that perhaps you shouldn’t be doing this. It sounds like your idea might go against typical design patterns for Android. If your menu is changing in response to a user selection, for example, you should use contextual action mode instead.

    • From the Action Bar API Guide:

      As a general rule, all items in the options menu (let alone action items) should have a global impact on the app, rather than affect only a small portion of the interface. […] So, even before deciding whether a menu item should appear as an action item, be sure that the item has a global scope for the current activity.

    • From the Menu API Guide:

      You should never change items in the options menu based on the View currently in focus. When in touch mode (when the user is not using a trackball or d-pad), views cannot take focus, so you should never use focus as the basis for modifying items in the options menu. If you want to provide menu items that are context-sensitive to a View, use a Context Menu.


    Barring that, if you do want to change the menu items as you have described, you should make the change in onPrepareOptionsMenu(). When the event occurs that requires changing the menu items, put the relevant information into a field and call invalidateOptionsMenu(). Override onPrepareOptionsMenu() and check the value of the field to determine which menu items to add/remove.

    (It would also work to call invalidateOptionsMenu() and override onCreateOptionsMenu() to modify which menu items should be shown, although this approach is not recommended.)

    More from the Menu API Guide:

    You should use onCreateOptionsMenu() only to create the initial
    menu state and not to make changes during the activity lifecycle.
    If you want to modify the options menu based on events that occur
    during the activity lifecycle, you can do so in the
    onPrepareOptionsMenu() method.

    This method passes you the Menu object as it currently exists so you
    can modify it, such as add, remove, or disable items. (Fragments also
    provide an onPrepareOptionsMenu() callback.)

    • On Android 2.3.x and lower, the system calls onPrepareOptionsMenu()
      each time the user opens the options menu (presses the Menu button).

    • On Android 3.0 and higher, the options menu is considered to always be
      open when menu items are presented in the action bar. When an event
      occurs and you want to perform a menu update, you must call
      invalidateOptionsMenu() to request that the system call
      onPrepareOptionsMenu().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason there's a variable called d that is defined immediately after I
For some reason, I can not get this dialog to show up on the
For some reason, I can't get the John Resig micro template to work. I've
For some reason I can't get something to work. All I want to do
For some reason I can't detect I can't set a z index for any
For some reason, I am getting a weird overlapping dropdown menu glitch. It works
For some reason, I can't update the second label. I tested it by asking
For some reason when I make a GET request, it seems to go into
For some reason, my script isn't writing out the text after I remove the
For some reason I can't horizontally scroll through my linear layout... I tried this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.