Android: LoaderCallbacks.OnLoadFinished called twice

前端 未结 10 2313
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 11:05

I noticed strange situation using Android Loaders and Fragments. When I invoke LoaderManager.initLoader() after orientation change onLoadFinished is not called (although doc

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 11:14

    The problem is that it called twice:
    1. from Fragment.onStart
    2. from FragmentActivity.onStart

    The only difference is that in Fragment.onStart it checks if mLoaderManager != null. What this means is if you call getLoadManager before onStart, like in onActivityCreated, it will get/create load manager and it will be called. To avoid this you need to call it later, like in onResume.

提交回复
热议问题