避免与AsyncTask的重装活动的方向变化的机器人 [英] Avoid reloading activity with asynctask on orientation change in android

查看:117
本文介绍了避免与AsyncTask的重装活动的方向变化的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免重装用的AsyncTask类活动活动,当用户改变方向,在Android的?任何人都可以举个例子?

How do I avoid reloading the activity with asynctask class in activity when the user changes orientation, in android? Can anybody give an example?

感谢

推荐答案

奇拉格已经正确地指出了解决方案。 我只想补充一点,活动的启动无关的AsyncTask的在里面。默认情况下,当有任何配置的变化,该活动将重新启动,除非在配置变化由活动显式处理。这是通过在manifest文件中的条目进行。

Chirag have already correctly pointed out the solution. I just want to add that, restart of Activity has nothing to do with the AsyncTask in it. By default, when there are any config changes,the activity is restarted UNLESS the config change is explicitly handled by the Activity. This is done by making an entry in manifest file.

穿过此链接:http://developer.android.com/guide/topics/manifest/activity-element.html#config

注意:检查code的设备没有在模拟器。因为我曾遇到类似的问题更早。同样的code没有工作的仿真器,但它的工作对设备完美。因此,增加对安卓入门:configChanges 在清单和检查Android设备,而不是仿真器上的应用程序

NOTE: Check the code on a device not on emulator. Because I had faced similar problem earlier. The same code didn't worked on emulator but it worked on device perfectly. So add the entry for android:configChanges in manifest and check the application on a android device instead of emulator.

和我第二@hackbod。 不要只在必要!

And I second @hackbod. Do it only if necessary!

这篇关于避免与AsyncTask的重装活动的方向变化的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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