找回密码
 立即注册
AsyncTaskAndroid线程the | android开发 2022-11-23 38 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
我们都认识,AndroidUI是线程不安全的,如果想要在子线程里进行UI操作,就需要凭借Android的异步消息管理机制。之前我也写过了一篇文章从源码层面分析了Android的异步消息管理机制,感兴趣的朋友可以参考AndroidHandler、Message完全解析,带你从源码的观点完全理解。不过为了愈加方便我们在子线程中更新UI元素,Android从1.5版本就引入了一个AsyncTask类,使用它就可以十分灵敏方便地从子线程切换到UI线程,我们本篇文章的主角也就正是它了。AsyncTask很早就出现在Android的API里了,所以我相信大多数朋友对它的用法都已经十分理解。不过今日我仍是预备从AsyncTask的基本用法开始讲起,然后我们再来一同分析下AsyncTask源码,看看它是如何实现的,最终我会介绍一些关于AsyncTask你所不认识的秘密。

(We all know that Android UI is not thread safe. If you want to perform UI operations in sub threads, you need to rely on Android's asynchronous message management mechanism. I also wrote an article before that which analyzed the asynchronous message management mechanism of Android from the source code level. If you are interested, you can refer to the complete analysis of Android Handler and Message to guide you to fully understand it from the source code point of view. However, in order to make it easier for us to update UI elements in the sub thread, Android has introduced an AsyncTask class since version 1.5. With this class, we can switch from the sub thread to the UI thread in a very flexible and convenient way. It is also the protagonist of this article. AsyncTask has appeared in the Android API for a long time, so I believe most friends have fully understood its usage. But today I'm going to start with the basic usage of AsyncTask. Then let's analyze the source code of AsyncTask and see how it is implemented. Finally, I'll introduce some secrets about AsyncTask that you don't know.)

[下载]10082600264.rar




上一篇:尚学堂_高明鑫_android视频教程
下一篇:Android Fragment完全解析,关于碎片你所需知道的一切