OnLoadFinished()调用两次 [英] OnLoadFinished() called twice

查看:1960
本文介绍了OnLoadFinished()调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚,如果我做错事就装载机。我使用的是支持库,和我有一个片段中的onCreate()调用initLoader()设置自己为LoaderCallbacks,然而在旋转它接收两次onLoadFinished(结果),一次是在调用init的结果(和它已经具有数据),并且一旦作为FragmentActivity的结果通过所有装载机在ONSTART循环()和传递结果,因为它已经具有的数据。

I'm trying to figure out if I'm doing something wrong with respect to Loaders. I'm using the support library, and I have a Fragment which in onCreate() calls initLoader() setting itself as the LoaderCallbacks, however on a rotation it is receiving the result twice in onLoadFinished(), once as a result of calling init (and it already having the data), and once as a result of FragmentActivity looping through all Loaders in onStart() and delivering the result since it already has the data.

如果我只调用初始化一次(在第一次启动的片段),它并没有为自己的回调对Loader,因此不会收到呼叫onLoadFinished的。它好像onLoadFinished应该只被调用一次,因为一些昂贵的东西可能在onLoadFinished()来完成(如清除列表适配器等),所以我只是想弄清楚,如果这是一个错误,或者如果我只是在调用init在错误的时间或别的东西。

If I only call init once (on first launch of the Fragment), it doesn't set itself as the callback for the Loader so it doesn't receive a call to onLoadFinished at all. It seems as though onLoadFinished should only be called once since some expensive things may be done in onLoadFinished() (such as clearing list adapters, etc.), so I'm just trying to figure out if this is a bug or if I am just calling init at the wrong time or something else.

任何人有任何了解这个问题?

Anyone have any insight to this issue?

推荐答案

我也有类似的问题,原因在于我有 initLoader restartLoader 在我的code。根据用户的动作,我的查询可能会改变,所以我需要重新启动我的装载机。

I had a similar problem and the cause was that I had initLoader and restartLoader in my code. Depending on user's action, my query could change, so I needed to restart my loader.

解决的办法是只使用 restartLoader ,即使在 onResume 回调方法替换 initLoader restartLoader

The solution was to use only restartLoader, even in onResume callback method replace initLoader with restartLoader.

这篇关于OnLoadFinished()调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆