Search code examples
androidandroid-activityandroid-fragmentsactivity-lifecyclefragment-lifecycle

Activity and Fragment Lifecycle, does the onResume fire one after the other?


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().


Solution

  • 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:

    enter image description here

    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.