What is the Difference between onResume() and onPostResume() in Activity Life Cycle?
Asked Answered
P

2

5

While Learning Activity LifeCycle in Android, I am confused about these two methods. I tried to implement both of them separately and are working fine. So, What's the difference between these two twins?

Papke answered 18/4, 2020 at 18:12 Comment(6)
You can check my answer as correctHora
sure, I have checkedPapke
will you please upvote my new Question which is very important and need some attention from developers. ThanksPapke
Which question?Hora
Which I added recently link: #61304320Papke
I gave answer to that questionHora
H
2

onPostResume :

Called when activity resume is complete (after activity's {@link #onResume} has been called). Applications will generally not implement this method; it is intended for system classes to do final setup after application resume code has run.

It will do following things

It will ensure that screen is visible to user and will do the final set up for activity.

Remove any pending posts of messages with code 'what' that are in the message queue.

Check all fragment gets resumed and Moves all Fragments managed by the controller's FragmentManager into the resume state.

Execute any pending actions for the Fragments managed by the controller's FragmentManager.

If you check it life cycle vise it worked like below

onResume() - Activity

onResume() - Fragment check third point as explained above

onPostResume() - Activity See here please: Activity life cycle methods : onPostResume significance

Hora answered 18/4, 2020 at 18:16 Comment(0)
C
4

onResume():

protected void onResume() Called after onRestoreInstanceState(Bundle), onRestart(), or onPause(), for your activity to start interacting with the user. This is an indicator that the activity became active and ready to receive input. It is on top of an activity stack and visible to user.

On platform versions prior to Build.VERSION_CODES.Q this is also a good place to try to open exclusive-access devices or to get access to singleton resources. Starting with Build.VERSION_CODES.Q there can be multiple resumed activities in the system simultaneously, so onTopResumedActivityChanged(boolean) should be used for that purpose instead.

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

If you override this method you must call through to the superclass implementation.

 onPostResume():

protected void onPostResume() Called when activity resume is complete (after onResume() has been called). Applications will generally not implement this method; it is intended for system classes to do final setup after application resume code has run.

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

If you override this method you must call through to the superclass implementation.

Cuticula answered 18/4, 2020 at 18:21 Comment(0)
H
2

onPostResume :

Called when activity resume is complete (after activity's {@link #onResume} has been called). Applications will generally not implement this method; it is intended for system classes to do final setup after application resume code has run.

It will do following things

It will ensure that screen is visible to user and will do the final set up for activity.

Remove any pending posts of messages with code 'what' that are in the message queue.

Check all fragment gets resumed and Moves all Fragments managed by the controller's FragmentManager into the resume state.

Execute any pending actions for the Fragments managed by the controller's FragmentManager.

If you check it life cycle vise it worked like below

onResume() - Activity

onResume() - Fragment check third point as explained above

onPostResume() - Activity See here please: Activity life cycle methods : onPostResume significance

Hora answered 18/4, 2020 at 18:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.