Android中的Looper对象详细介绍

来源:爱站网时间:2020-03-31编辑:网友分享
Looper对象通常要结合其他对象,才能实现某个效果,其实简单的来说Looper就是一个管理对象,下面爱站技术频道带大家来学习Android中的Looper对象详细介绍吧,下文将为你细细讲解。

Looper对象通常要结合其他对象,才能实现某个效果,其实简单的来说Looper就是一个管理对象,下面爱站技术频道带大家来学习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中的Looper对象详细介绍,小编觉得还是蛮靠谱的,因为我们项目本来就需要这个对象,Looper对象的好处也的很多的哦。

上一篇:ubuntu用wifi连接android调试程序的步骤

下一篇:android开发中使用java观察者模式

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载