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?
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
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.
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
© 2022 - 2024 — McMap. All rights reserved.