本文介绍了安卓:LoaderCallbacks.OnLoadFinished叫了两声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到采用了Android装载机和片段奇怪的现象。当我方向更改后调用LoaderManager.initLoader()onLoadFinished不叫(尽管文档建议我应该ppared这个$ P $),但是在此之后叫了两声。这里是链接发布在谷歌组,描述了同样的情况<一href="https://groups.google.com/forum/?fromgroups#!topic/android-developers/aA2vHYxSskU">https://groups.google.com/forum/?fromgroups#!topic/android-developers/aA2vHYxSskU 。我写了示例应用程序中,我只简单的初始化加载在Fragment.onActivityCreated()检查,如果发生这种情况,它确实。任何人都注意到了这一点?

I noticed strange situation using Android Loaders and Fragments. When I invoke LoaderManager.initLoader() after orientation change onLoadFinished is not called (although documentation suggests I should be prepared for this) but it is called twice after this. Here is link to post in google groups which describe the same situation https://groups.google.com/forum/?fromgroups#!topic/android-developers/aA2vHYxSskU . I wrote sample application in which I only init simple Loader in Fragment.onActivityCreated() to check if this happens and it does. Anyone noticed this?

推荐答案

您可以把您的片段的onResume()回调内部initLoader()方法;那么装载机的onLoadFinished()将不会被两次再调用。

You can put the initLoader() method inside your Fragment's onResume() callback; then the Loader's onLoadFinished() will not be called twice anymore.

    @Override
public void onResume()
{
    super.onResume();
    getLoaderManager().initLoader(0, null, this);
}

这篇关于安卓:LoaderCallbacks.OnLoadFinished叫了两声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 06:37