手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android中的Looper对象详细介绍
Android中的Looper对象详细介绍
摘要:Java官网对Looper对象的说明:publicclassLooperextendsObjectClassusedtorunamessag...

Java 官网对Looper对象的说明:

public class Looperextends Object

Class used to run a message loop for a thread. Threads by default do not have a message loop associated with them; to create one, call prepare() in the thread that is to run the loop, and then loop() to have it process messages until the loop is stopped.

Most interaction with a message loop is through the Handler class.

This is a typical example of the implementation of a Looper thread, using the separation of prepare() and loop() to create an initial Handler to communicate with the Looper.

复制代码 代码如下:

class LooperThread extends Thread {

public Handler mHandler;

public void run() {

Looper.prepare();

mHandler = new Handler() {

public void handleMessage(Message msg) {

// process incoming messages here

}

};

Looper.loop();

}

}

主要方法:

static void loop() : Run the message queue in this thread.

static void prepare() : Initialize the current thread as a looper.

【Android中的Looper对象详细介绍】相关文章:

Android中的文件I/O操作

Android实现语音识别代码

Android开发笔记之:消息循环与Looper的详解

Android中Service(后台服务)详解

Android 布局控件之LinearLayout详细介绍

基于Android LayoutInflater的使用介绍

Android内存调试命令

Android应用程序签名步骤及相关知识介绍

Android Mms之:PDU的使用详解

Android中的Adapter简单介绍

精品推荐
分类导航