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

后端 未结 2 922
夕颜
夕颜 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-13 00:16

    Timer task is not related with fragment life cycle. You can cancel timer when you finished your job with that fragment. Fragment's onStop method is good place to do that.

    public void onStop() {
        super.onStop();
        timer.cancel();
    }
    

提交回复
热议问题