问题描述
我仍然在试图找到正确的设计模式时的AsyncTask
处理S和屏幕旋转。我读这commonsware博客帖子可链接到this code ,但onRetainNonConfigurationInstance方法现在是很precated。在文档中的魔术句子:没有消息,切换到下一个活动中处理的担保,简化了活动对象使用......这是什么此方法做一个真正的重要组成部分。我没有看到使用它的建议setRetainInstance()能完成相同的目标
I am still trying to find the "correct" design pattern when dealing with AsyncTask
s and screen rotation. I read this commonsware blog post which links to this code, but the onRetainNonConfigurationInstance method is now deprecated. The magic sentence in the documentation states "The guarantee of no message handling during the switch to the next activity simplifies use with active objects..." which is a truly critical part about what this method did. I don't see its suggestion of using setRetainInstance() being able to accomplish the same goal.
我也看了帖子such这一个的一个回答就是真的不折不扣的坏黑客仅包括90%的用例(即如果你的任务正在运行,然后一个电话进来会发生什么情况,该解决方案将无法正常工作)。
I also saw posts such as this one whose number one answer is really nothing short of a bad hack which only covers 90% of use cases (ie. what happens if your task is running and then a phone call comes in, that solution will not work).
有人建议审查code here为AsyncTask的例子,但除非我被密集的,我不认为他们会被任何地方使用的应用程序(当使用<一个href="http://www.google.com/$c$csearch#search&q=AsyncTask+package%3ahttp://shelves%5C.google$c$c%5C.com">search功能对谷歌code)
It was suggested to review the code here for AsyncTask examples but unless I am being dense, I don't see them being used anywhere in the application (when using the search feature on google code)
这个问题显然被问过很多次,但我还没有看到一个最新的,正确的asnwer。如果存在,请回答和关闭,如果你要重复,但至少回答! :)
This question has obviously been asked many times but I have not seen an up to date, proper asnwer. If one exists, please answer and close as duplicate if you must, but at least answer! :)
This是另一个链接负责审查一样,去precated方法。
This is another link which reviews the same, deprecated method.
推荐答案
这只是德precated对蜂窝及以上,且它会工作得很好对这些呢。 新的方法是使用装载机(可以使用兼容性库让那些在pre-HC版本)或保留片段。如果你调用 setRetainInstance()
原样传递到新创建的活动(他们实际使用 onRetainNonConfigurationInstance
的实例 FragmentActivity ),所以它实际上是相同的,你现在有什么。
It's only deprecated on Honeycomb and above, and it will work just fine on those too. The 'new' way is to use loaders (you can use the compatibility library to get those in pre-HC versions) or retained fragments. If you call setRetainInstance()
the instance passed as is to the newly created activity (they actually use onRetainNonConfigurationInstance
in the FragmentActivity
of the compatibility library), so it's effectively the same as what you have now.
这篇关于AsyncTask的与屏幕旋转 - onRetainNonConfigurationInstance德precated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!