Android Chinese API (127) -- MessageQueue

Source: Internet
Author: User

 

Preface

This chapter is about android. OS. MessageQueue, Android 3.1 r1, translated from "strongxu", welcome to visit his meager "http://t.qq.com/strongxu", thanks again "strongxu "! Welcome to join in Android Chinese translation, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://goo.gl/6vJQl

 

 

 

MessageQueue

Translator's signature: strongxu

Translator's microblog: http://t.qq.com/strongxu

Version: Android 3.1 r1

 

Structure

Inheritance relationship

Public class MessageQueue extends Object

Java. lang. Object

Android. OS. MessageQueue

 

Class Overview

A low-level class that stores the message list. These messages are distributed by logoff objects. Messages are not directly added to MessageQueue, but are added through the MessageQueue. IdleHandler object associated with the logoff object.

Call logoff. myQueue to obtain the MessageQueue of the current thread.

 

Common Methods

Public final voidAddIdleHandler(MessageQueue. IdleHandler handler)

Add a new MessageQueue. IdleHandler to the message queue. When the call of IdleHandler. queueIdle () returns false, the MessageQueue. IdleHandler will automatically remove it from the message queue. You can also call removeIdleHandler (MessageQueue. IdleHandler) to remove MessageQueue. IdleHandler from the message queue.

This method is thread-safe.

Parameters

The IdleHandler to add.

 

Public final voidRemoveIdleHandler(MessageQueue. IdleHandler handler)

Remove MessageQueue. IdleHandler added by calling addIdlehandler (MessageQueue. IdleHandler) from the queue. If handler is not in the current idle list, do nothing.

Parameters

The IdleHandler to remove.

 

Protected Methods

Protected voidFinalize()

Called before the object is recycled by the VM. This occurs only when the Garbage Collector detects that all running threads no longer use this object.

This method can be used to release system resources or perform other cleanup tasks before objects are recycled. By default, the implementation of this method is empty, which is also expected by the VM, but the subclass can override this method. If this method is executed, an uncaptured exception is thrown, causing the program to end immediately. Otherwise, the exception is ignored.

Note that the VM ensures that the finalize method of any object can be called at most once, but it does not guarantee when or whether finalize will be called. For example, the finalize method of object B can postpone the execution of finalize of object A, so it will delay the collection of memory space of object. For security, ReferenceQueue is used, because during garbage collection, it provides more control methods in the way the VM handles references.

 

Supplement

Article Selection

Android thread Handler Message Queue AsyncTask thread model

Handler, lofter, MessageQueue and Thread in Android

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.