异步任务的缺点(如果有) [英] Down sides of Async Task If Any
问题描述
我知道您在AsnycTask中的非UI代码中使用得很好,但是我只是想知道在使用AsyntTask时是否有任何问题?我没有任何产生问题的代码.但是我很想知道如果您对AsnycTask有任何不好的经验,并希望与大家分享.
I know you are using it quite well with your Non-UI codes in AsnycTask but I am just wondering if there is any kind of problem while using AsyntTask? I am not having any code which produce the problem. But I am just curious to know Any bad experience if you have with AsnycTask and would like to share it.
推荐答案
- 内存泄漏:
即使活动被破坏,AsyncTask仍保留活动的引用,因为它必须使用回调方法来更新UI.
Even though activity is destroyed, AsyncTask holds the Activity's reference since it has to update UI with the callback methods.
- 取消AsyncTask:
使用cancel()API取消AsyncTask不会确保该任务将立即停止.
cancelling AsyncTask using cancel() API will not make sure that task will stop immediately.
- 数据丢失:
完成屏幕方向后.活动被销毁并重新创建,因此AsysncTask将保存无效的活动引用,并且在更新UI时会遇到麻烦.
When screen orientation is done. Activity is destroyed and recreated, hence AsysncTask will hold invalid reference of activity and will trouble in updating UI.
这篇关于异步任务的缺点(如果有)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!