Android中的Looper对象详细介绍
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 Navigation TabBar控件实现多彩标签栏
这篇文章主要为大家详细介绍了Android Navigation TabBar控件实现多彩标签栏的相关代码,感兴趣的小伙伴们可以参考一下2016-05-05详解如何在Android Studio中添加RecyclerView-v7支持包
本篇文章主要介绍了详解如何在Android Studio中添加RecyclerView-v7支持包,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2018-02-02解决flutter 错误: 程序包androidx.lifecycle不存在问题
这篇文章主要介绍了解决flutter 错误: 程序包androidx.lifecycle不存在问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-09-09
最新评论