I am wondering what the proper order goes when a user returns to an Activity
from the Home Screen
.
Will the Activity's onResume()
execute first, and then the Fragment's onResume()
execute after? Does it do it in order, or will it do it concurrently?
I put some code in my Fragment's onResume() but it doesn't seem to be firing after the Activity's onResume().
A fragment life cycle is closely related to the lifecycle of its host activity which means when the activity is in the pause state, all the fragments available in the activity will also stop. Fragments added to the Android API in Android 3.0 which API version 11 to support flexible UI on large screens.
Each Fragment instance has its own lifecycle. When a user navigates and interacts with your app, your fragments transition through various states in their lifecycle as they are added, removed, and enter or exit the screen.
onResume() will never be called before onCreate() . Show activity on this post. onResume() will always be called when the activity goes into foreground, but it will never be executed before onCreate() .
I am wondering what the proper order goes when a user returns to an Activity from the Home Screen.
Activity's onResume() execute and the Fragment's onResume() execute after. Here is my screen shot of the log:
Will the Activity's onResume() execute first, and then the Fragment's onResume() execute after? Does it do it in order, or will it do it concurrently?
Yes, the two onResume() method execute in order, because they are all executed on the main thread(also called ui thread, it's a single thread), so there is no concurrent problem.
I put some code in my Fragment's onResume() but it doesn't seem to be firing after the Activity's onResume().
I think there is something wrong with your code, you can check it again or post it here, so someone may point your mistake.
The fragments onResume()
or onPause()
will be called only after the Activities onResume()
or onPause()
is called. They are tightly coupled to the Activity
.
Read the Fragment Lifecycle section of this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With