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 4099852
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:29:25+00:00 2026-05-20T20:29:25+00:00

Trying to do the following (code is in the main activity): private MenuItem mainMenuSync

  • 0

Trying to do the following (code is in the main activity):

private MenuItem mainMenuSync = null;

public void onCreate(Bundle savedInstanceState) {
  ...
  mainMenuSync = (MenuItem) findViewById(R.id.main_menu_sync);
}

private class Synchronize extends AsyncTask<Void, Void, Void> {
  ...

  @Override
  protected void onPreExecute() {
    mainMenuSync.setEnabled(false);
  }

But it fails. What I am doing wrong?
(This menu item really starts this ASyncTask and I would like to avoid starting it again)

  • 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-05-20T20:29:26+00:00Added an answer on May 20, 2026 at 8:29 pm

    Since your mainMenuSync is coming from a Main Menu, I guess you are creating it in onCreateOptionsMenu, isn’t it?

    If that’s the case, filling its value using onCreate would have no effect, since by that moment, your main menu isn’t inflated from the xml yet, and I wonder you should already FC before seeing anything on the screen.

    Main Menu is not the same as other UI item in Android, which in most use cases they are inflated on demand in onCreateOptionsMenu and reused next in onPrepareOptionsMenu. What you can do is to declare a flag to enable/disable that item:

    boolean showMainMenuSync = true;
    
    onPrepareOptionsMenu(Menu menu){
        super.onPrepareOptionsMenu(menu);
        menu.findItem(R.id.main_menu_sync).setEnabled(showMainMenuSync);
    }
    

    which of course showMainMenuSync should be changing by your async task.

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

Sidebar

Related Questions

I am trying to compile the following code: private String dataToString(){ Map data =
I've got a WinForms app with the following code: static void Main() { IKernel
I have a main activity that launches a child activity using the following code:
I am trying the following code: <?php $link = mysql_connect('localhost', 'root', 'geheim'); if (!$link)
I'm trying to use the following code but it's returning the wrong day of
I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user
I am trying to use the following code to write data into an excel
I am trying to use the following code, which I have not been able
I am trying to use the following code to export tables from access to
I have the following code, I'm trying to get a table with 4 columns

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.