Fragment 类的哪种生命周期方法最适合调用 AsyncTask 上的 >execute()
方法onCreate()
、onAttach()
还是 onActivityCreated()
?我想在片段第一次显示时将数据加载到 TextView 中。
Which lifecycle method of the Fragment class is the best to call the execute()
method on a AsyncTask onCreate()
, onAttach()
or onActivityCreated()
? I want to load data into TextViews on the Fragment's first time it is shown.
发布评论
评论(1)
我会使用 onCreate() 因为你只需要第一次而不是恢复后。请参阅有关 Fragments 的 Android 文档,以确保您理解完全。它有一个很好的片段生命周期图像,我将其放在下面以供参考。
I would use onCreate() as you only want it the first time and not after resuming. Look at the the Android documentation on Fragments though to make sure you understand fully. It has a nice fragment lifecycle image which I have put below for reference.