I have an android activity that needs to call another activity (to get a password from the user) before its own screen is brought up. My code currently does this by calling startActivity() from within onResume(); it sort of works, but I have been getting inconsistent behaviour. Can anyone tell me whether this approach is legal or not (and if not, how should I do it) ?
Thanks, Richard.
Calling
startActivity()inonResume()is absolutely fine. I have many activities which do this, often in reaction to events which have happened while the activity was stopped.All
startActivity()does is tell Android to start the new activity and add it to the top of the back stack when the main thread becomes available, which in this instance will be after Android has finished calling all the necessary lifecycle callbacks on the current activity.If you are experiencing odd behaviour I doubt is related to this.