简体   繁体   中英

android app change menu on startup, at what stage?

In my Java Android App's MainActivity I have a Toolbar on top (set via setSupportActionBar(Toolbar) ) with a youAreloggedIn icon. On starting the app and before it shows or soon after, I want to make a remote connection, check if user is logged in to that remote server and change the icon to indicate that: a lock if not logged in (which is the default) or an opened-lock if user is logged in.

My question is in which callback I should place this code (network enquire and icon change). Right now I have the code at the end of onCreateOptionsMenu() after the menu is inflated.

Is there another onXXX() callback which is more suitable?

Apparently, onStart() is called before the menu is inflated, And so, I can't change icons in there before the menu in the toolbar is created!

Something like onSteadyState() perhaps?

What you need is invalidateOptionsMenu() , you can call it after the network fetch with can be called asynchronously in onstart()

Read more about this here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM