有时打电话initLoader后没有得到onCreateLoader回调 [英] Sometimes don't get onCreateLoader callback after calling initLoader

查看:335
本文介绍了有时打电话initLoader后没有得到onCreateLoader回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以加载该活动将显示数据被创建时调用initLoader的活动。通常情况下,这工作正常。我必须设置看,一切发生的顺序断点。首先,我打电话initLoader,然后我得到了OnCreateLoader回调,那么回调OnLoadFinished,那么一切都很好。

I have an activity that calls initLoader when it is created in order to load the data that the activity will display. Normally, this works fine. I have breakpoints set to see the order that everything happens. First I call initLoader, then I get the OnCreateLoader callback, then the OnLoadFinished callback, then everything is great.

不过,我注意到,如果我改变了对我的Andr​​oid的方向,我没有得到OnCreateLoader回调或回调OnLoadFinished,导致没有在网页上显示的数据。我仍然得到我的电话initLoader断点,所以我知道正在发生的事情,但我没有得到一个错误,我无法找到任何文件,解释我为什么不打电话initLoader后得到一个回调。

However, I noticed that if I changed the orientation on my Android that I don't get the OnCreateLoader callback or the OnLoadFinished callback, resulting in no data displayed on the page. I still get my breakpoint on the initLoader call so I know that is happening, but I don't get an error and I can't find any documentation explaining why I wouldn't get a callback after calling initLoader.

有趣的是,我得到的回调,如果我回到原来的方向。

Interestingly, I do get the callbacks if I return to the original orientation.

因此​​,要总结:

我开始在纵向活动


  • 我叫initLoader

  • 我得到onCreateLoader和onLoadFinished回调

然后我更改为横向


  • 我叫initLoader

  • 没有onCreateLoader或onLoadFinished回调

我改回为纵向


  • 我叫initLoader

  • 我得到onCreateLoader和onLoadFinished回调

同样,如果我开始在横向模式下的活动我得到的回调。然后,如果我切换到肖像,我不知道。然后,如果我切换到横向,我再次得到了回调。

Similarly, if I start the activity in landscape mode I get the callbacks. Then, if I switch to portrait, I don't. Then, if I switch back to landscape I get the callbacks again.

有没有人有任何想法,这是怎么回事?

Does anyone have any idea what's going on?

推荐答案

我们已经看到了这个同样的问题在ViewPager片段。看来该装载机没有正确再次激活时恢复的片段。事实上,当片段被暂停,我们CursorLoader不再得到ContentObserver回调,因为我期望的那样。

We've seen this same problem with Fragments in a ViewPager. It appears that the loaders are not properly activated again when a fragment is resumed. In fact, when the fragment is paused, our CursorLoader no longer gets ContentObserver callbacks as I would expect.

我们的解决方法已经调用restartLoader(),它转储previous内容并重新加载数据。这将对作为destroyLoader相同的净影响(); initLoader(),但它会更有效。

Our workaround has been to call restartLoader() which dumps the previous contents and reloads the data. This would have the same net affect as destroyLoader(); initLoader(), but it will be more efficient.

这篇关于有时打电话initLoader后没有得到onCreateLoader回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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