IT. Expert System.

Android Reference

Looper


android.os

Class Looper



  • public class Looper
    extends 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();
          }
      }
    • Method Detail

      • prepare

        public static void prepare()
        Initialize the current thread as a looper. This gives you a chance to create handlers that then reference this looper, before actually starting the loop. Be sure to call loop() after calling this method, and end it by calling quit().
      • prepareMainLooper

        public static void prepareMainLooper()
        Initialize the current thread as a looper, marking it as an application's main looper. The main looper for your application is created by the Android environment, so you should never need to call this function yourself. See also: prepare()
      • getMainLooper

        public static Looper getMainLooper()
        Returns the application's main looper, which lives in the main thread of the application.
      • loop

        public static void loop()
        Run the message queue in this thread. Be sure to call quit() to end the loop.
      • myLooper

        public static Looper myLooper()
        Return the Looper object associated with the current thread. Returns null if the calling thread is not associated with a Looper.
      • setMessageLogging

        public void setMessageLogging(Printer printer)
        Control logging of messages as they are processed by this Looper. If enabled, a log message will be written to printer at the beginning and ending of each message dispatch, identifying the target Handler and message contents.
        Parameters:
        printer - A Printer object that will receive log messages, or null to disable message logging.
      • myQueue

        public static MessageQueue myQueue()
        Return the MessageQueue object associated with the current thread. This must be called from a thread running a Looper, or a NullPointerException will be thrown.
      • quit

        public void quit()
        Quits the looper. Causes the loop() method to terminate as soon as possible.
      • postSyncBarrier

        public final int postSyncBarrier()
        Posts a synchronization barrier to the Looper's message queue. Message processing occurs as usual until the message queue encounters the synchronization barrier that has been posted. When the barrier is encountered, later synchronous messages in the queue are stalled (prevented from being executed) until the barrier is released by calling removeSyncBarrier(int) and specifying the token that identifies the synchronization barrier. This method is used to immediately postpone execution of all subsequently posted synchronous messages until a condition is met that releases the barrier. Asynchronous messages (see Message.isAsynchronous() are exempt from the barrier and continue to be processed as usual. This call must be always matched by a call to removeSyncBarrier(int) with the same token to ensure that the message queue resumes normal operation. Otherwise the application will probably hang!
        Returns:
        A token that uniquely identifies the barrier. This token must be passed to removeSyncBarrier(int) to release the barrier.
      • removeSyncBarrier

        public final void removeSyncBarrier(int token)
        Removes a synchronization barrier.
        Parameters:
        token - The synchronization barrier token that was returned by postSyncBarrier().
        Throws:
        IllegalStateException - if the barrier was not found.
      • getThread

        public Thread getThread()
        Return the Thread associated with this Looper.
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 853 / . Delta: 0.03554 с