AsyncTask的与屏幕旋转 - onRetainNonConfigurationInstance德precated [英] AsyncTask with screen rotation - onRetainNonConfigurationInstance deprecated

查看:164
本文介绍了AsyncTask的与屏幕旋转 - onRetainNonConfigurationInstance德precated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍然在试图找到正确的设计模式时的AsyncTask 处理S和屏幕旋转。我读这commonsware博客帖子可链接到<一个href="https://github.com/commonsguy/cw-android/blob/master/Rotation/RotationAsync/src/com/commonsware/android/rotation/async/RotationAsync.java">this code ,但<一个href="http://developer.android.com/reference/android/app/Activity.html#onRetainNonConfigurationInstance%28%29">onRetainNonConfigurationInstance方法现在是很precated。在文档中的魔术句子:没有消息,切换到下一个活动中处理的担保,简化了活动对象使用......这是什么此方法做一个真正的重要组成部分。我没有看到使用它的建议<一href="http://developer.android.com/reference/android/app/Fragment.html#setRetainInstance%28boolean%29">setRetainInstance()能完成相同的目标

I am still trying to find the "correct" design pattern when dealing with AsyncTasks 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.

我也看了帖子<一href="http://stackoverflow.com/questions/2620917/how-to-handle-an-asynctask-during-screen-rotation">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 <一个href="http://stackoverflow.com/questions/2620917/how-to-handle-an-asynctask-during-screen-rotation/2624569#2624569">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! :)

<一个href="http://blog.doityourselfandroid.com/2010/11/14/handling-progress-dialogs-and-screen-orientation-changes/">This是另一个链接负责审查一样,去precated方法。

This is another link which reviews the same, deprecated method.

推荐答案

这只是德precated对蜂窝及以上,且它会工作得很好对这些呢。 新的方法是使用装载机(可以使用兼容性库让那些在pre-HC版本)或保留片段。如果你调用 setRetainInstance()原样传递到新创建的活动(他们实际使用 onRetainNonConfigurationInstance 的实例<兼容性库的code> 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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