当Asynctask任务运行时,屏幕方向发生变化时会发生什么? [英] What will happen while Asynctask task is running ,when the Screen orientation is change?

查看:108
本文介绍了当Asynctask任务运行时,屏幕方向发生变化时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当Asynctask任务正在运行时,当屏幕方向发生变化时会发生什么?

解决方案

旋转屏幕将导致当前的Activity被销毁并且新的一个重新创建。如果发生这种情况时AsyncTask正在运行,它可能会产生两个后果:

1.新的Activity实例可能会通过再次启动后台工作而浪费宝贵的资源,而不知道旧的AsyncTask仍然存在运行。

2.当旧的AsyncTask最终完成时,它将尝试将其结果报告回已经销毁的旧Activity实例。


查看此:

http:// androidresearch。 wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/ [ ^ ]



-KR

AsyncTask将继续在后台运行并在尝试将结果发布到UI线程时使应用程序崩溃。您可以使用无头片段来托管AsyncTask,并确保仅在恢复活动时才完成UI线程上的帖子。


What will happen while Asynctask task is running ,when the Screen orientation is change?

解决方案

Rotation of the screen will cause the current Activity to be destroyed and new one recreated. If an AsyncTask is running when this happens, it could give rise to two consequences:
1. The new Activity instance might waste valuable resources by firing up the background work again, unaware that the old AsyncTask is still running.
2. When the old AsyncTask eventually finishes, it will attempt to report its results back to the old Activity instance which has already destroyed.


See this :
http://androidresearch.wordpress.com/2013/05/10/dealing-with-asynctask-and-screen-orientation/[^]

-KR


AsyncTask will continue to run in the background and crash your app when it tries to post the result on the UI thread. You can use headless fragments to host an AsyncTask and ensuring that posts on the UI thread are done only when the Activity is resumed.


这篇关于当Asynctask任务运行时,屏幕方向发生变化时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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