Android中的Looper對象詳細(xì)介紹
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控件實(shí)現(xiàn)多彩標(biāo)簽欄
這篇文章主要為大家詳細(xì)介紹了Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄的相關(guān)代碼,感興趣的小伙伴們可以參考一下2016-05-05詳解如何在Android Studio中添加RecyclerView-v7支持包
本篇文章主要介紹了詳解如何在Android Studio中添加RecyclerView-v7支持包,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02android屏幕圓角實(shí)現(xiàn)方法的示例代碼
本篇文章主要介紹了android屏幕圓角實(shí)現(xiàn)方法的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11解決flutter 錯誤: 程序包androidx.lifecycle不存在問題
這篇文章主要介紹了解決flutter 錯誤: 程序包androidx.lifecycle不存在問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-09-09Android中的Permission權(quán)限機(jī)制介紹
這篇文章主要介紹了Android中的Permission權(quán)限機(jī)制介紹,本文講解了權(quán)限策略、權(quán)限聲明、權(quán)限請求、獲取權(quán)限等內(nèi)容,需要的朋友可以參考下2015-04-04Android使用線程獲取網(wǎng)絡(luò)圖片的方法
這篇文章主要為大家詳細(xì)介紹了Android使用線程獲取網(wǎng)絡(luò)圖片的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-06-06Android實(shí)現(xiàn)IOS相機(jī)滑動控件
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)IOS相機(jī)滑動控件的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08