What is the lifecycle of a fragment when replace() is called?

后端 未结 2 937
夕颜
夕颜 2021-02-12 23:34

I have a number of fragments which are dynamically added using the following code:

private class DrawerItemClickListener implements ListView.OnItemClickListener          


        
2条回答
  •  我寻月下人不归
    2021-02-12 23:59

    I would kill any timers or Async work in onStop()

    http://developer.android.com/guide/components/fragments.html#Lifecycle

    Quoting the API doc:

    Stopped
    The fragment is not visible. Either the host activity has been stopped or the fragment has been removed from the activity but added to the back stack. A stopped fragment is still alive (all state and member information is retained by the system). However, it is no longer visible to the user and will be killed if the activity is killed.

    Fragment lifecycle:

    Fragment lifecycle

提交回复
热议问题