Life cycle comparison between fragment and activity in Android

Fragments must exist depending on activities, so the life cycle of activities will directly affect the life cycle of fragments. This picture on the official website well illustrates the relationship between the two:

You can see that fragment has several additional lifecycle callback functions more than activity:

Note: if you override all other methods except oncreateview, you must call the implementation of the method by the parent class.

Scene demonstration:

Switch to this fragment

Screen off:

Screen unlock

Switch to another fragment:

Switch back to its fragment:

Back to the desktop

Back to application

Exit application

It has more life cycles than activity. It is completely connected with activity, so we can make good use of it.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>