android runnable的作用,Android中Handler的作用和使用方法

public class Handler extends Object A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue. There are two main uses for a Handler: (1) to schedule messages and runnables to be executed as some point in the future; and (2) to enqueue an action to be performed on a different thread than your own. Handler的基本概念

包含线程队列和消息队列,实现异步的消息处理机制,跟web开发的ajax有异曲同工之妙。

创建一个Handler对象

Handler handler = new Handler();

将要执行的操作写在线程对象的run方法当中

Runnable updateThread = new Runnable(){

public void run(){<

你可能感兴趣的:(android,runnable的作用)