The use of Fragment (8) - life cycle

FragmentThe life cycle of the high version is a bit different from before. Probably SDK28 began to be revised. Here it Activityis compared with the records as follows; the program running version SDK30

YM--Activity: onCreate-->super_before
YM--Activity: onCreate-->super_after
YM-Fragment>: onAttach()
YM-Fragment>: onCreate()
YM--Activity: onCreate-->setContentView_after
YM-Fragment>: onCreateView()
YM-Fragment>: onStart()
YM--Activity: onStart()
YM--Activity: onResume()
YM-Fragment>: onResume()
YM-Fragment>: onPause()
YM--Activity: onPause()
YM-Fragment>: onStop()
YM--Activity: onStop()
YM-Fragment>: onDestroyView()
YM-Fragment>: onDestroy()
YM-Fragment>: onDetach()
YM--Activity: onDestroy()

The following flow can be remembered here, most of which are the first executed Fragmentlife cycle followed by Activitythe second executed life cycle. Except for onResume()the function, the function is triggered first Activity, followed by Fragment. In fact, it is understandable, after all , it Fragmentis attached to Activityit, so it needs Activityto receive the focus first, and then pass it to theFragment

Guess you like

Origin blog.csdn.net/Mr_Tony/article/details/122784020