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 Compose Column列表不自动刷新问题
这篇文章主要介绍了Android Compose Column列表数据更新列表不刷新的问题,总的来说这并不是一道难题,那为什么要拿出这道题介绍?拿出这道题真正想要传达的是解题的思路,以及不断优化探寻最优解的过程。希望通过这道题能给你带来一种解题优化的思路2023-01-01
Android Studio导入Project与Module的方法及实例
这篇文章主要介绍了Android Studio导入Project与Module的方法及实例的相关资料,需要的朋友可以参考下2017-04-04
在Visual Studio上构建C++的GUI框架wxWidgets的开发环境
这篇文章主要介绍了Visual Studio上构件C++的GUI框架wxWidgets开发环境的方法,wxWidgets是一个跨多个系统平台的图形化界面开发框架,并且可用语言不限于C++,需要的朋友可以参考下2016-04-04


最新评论