Android中的Looper對象詳細介紹
Java 官網(wǎng)對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.
相關(guān)文章
Android Navigation TabBar控件實現(xiàn)多彩標簽欄
這篇文章主要為大家詳細介紹了Android Navigation TabBar控件實現(xiàn)多彩標簽欄的相關(guān)代碼,感興趣的小伙伴們可以參考一下2016-05-05詳解如何在Android Studio中添加RecyclerView-v7支持包
本篇文章主要介紹了詳解如何在Android Studio中添加RecyclerView-v7支持包,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02解決flutter 錯誤: 程序包androidx.lifecycle不存在問題
這篇文章主要介紹了解決flutter 錯誤: 程序包androidx.lifecycle不存在問題,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09Android中的Permission權(quán)限機制介紹
這篇文章主要介紹了Android中的Permission權(quán)限機制介紹,本文講解了權(quán)限策略、權(quán)限聲明、權(quán)限請求、獲取權(quán)限等內(nèi)容,需要的朋友可以參考下2015-04-04Android使用線程獲取網(wǎng)絡(luò)圖片的方法
這篇文章主要為大家詳細介紹了Android使用線程獲取網(wǎng)絡(luò)圖片的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-06-06