源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中的Looper对象详细介绍

  • 时间:2022-03-22 21:28 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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.
[u]复制代码[/u] 代码如下:
  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.
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部