Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
92 views
in Technique[技术] by (71.8m points)

java - 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 ?

question from:https://stackoverflow.com/questions/65876813/android-app-change-menu-on-startup-at-what-stage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...