Lifecycle when calling the fragment replace or open new activity?

旧巷老猫 提交于 2019-12-04 10:19:06

When the fragment is added to the backstack, and then getting replaced or removed - it will go like this:

onPause() -> onSaveInstanceState() -> onStop() -> onDestroyView() 

If the fragment is removed, or replaced without getting added to the back stack, then following happens:

onPause() -> onSaveInstanceState() -> onStop() -> onDestroyView()  -> onDestroy() -> onDetach() -> Fragment is destroyed.

And when a activity starts another activity (source):

The order of lifecycle callbacks is well defined, particularly when the two activities are in the same process and one is starting the other. Here's the order of operations that occur when Activity A starts Acivity B:

Activity A's onPause() method executes. Activity B's onCreate(), onStart(), and onResume() methods execute in sequence. (Activity B now has user focus.) Then, if Activity A is no longer visible on screen, its onStop() method executes.

Because you need to call on your activity where your fragment is existing, to start a new activity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!