当前位置: 移动技术网 > IT编程>移动开发>Android > Android中的Looper对象详细介绍

Android中的Looper对象详细介绍

2019年07月24日  | 移动技术网IT编程  | 我要评论

陆武成被抓,部队砸酒店视频,菜园坝汽车站时刻表

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.

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网