Android Thread AsyncTask handler 应用区别

来源:互联网 发布:网络词方丈是什么意思 编辑:程序博客网 时间:2024/04/30 12:41

Android Thread  handler

AsyncTask 

都可以实现异步处理

AsyncTask  的出现就是为了 使UI 处理 更easy ,所以和UI 线程有关的 用 AsyncTask  最好

Thread  handler 主要是在线程里面,


Difference Handler and AsyncTask: Use AsyncTask when Caller thread is a UI Thread. This is what android document says:

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers

I want to emphasize on two points:

1) Easy use of the UI thread (so, use when caller thread is UI Thread).

2) No need to manipulate handlers. (means: You can use Handler instead of AsyncTask, but AsyncTask is an easier option).

There are many things in this post I haven't said yet, for example: what is UI Thread, of why it easier. You must know some method behind each kind and use it, you will completely understand why..

@: when you read Android document, you will see:

Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue


0 0
原创粉丝点击