Handler, Handler

Source: Internet
Author: User

Handler, Handler
Handler's Basic ConceptsHandler provides an asynchronous processing mechanism. There are two queues: one is the queue that puts the thread into, and the other is the message queue. Activity is a thread and download is another thread.Handler basic usageAdd to message queue immediately: post (Runnable object reference), remove from Message Queue: removeCallback (Runnable object reference) 1. create a Handler object 2. write the operation to be executed in the run method of the thread object. 3. in the run method, execute postDelayed (with two parameters) Method 4. call the post method referenced by Handler in the trigger eventRelationship between Handler and threadBy default, Handler is in the same thread as the Activity that calls it. Compile the Thread program: 1. Implement the runnable interface; 2. inherit the Thread class. Both methods have to implement the run method, but the start thread does not call the run method but calls the start method of the thread. If the run method is called directly, instead of actually starting a thread, the run method is executed in the current thread. Post (Runnable object), which is actually a direct run method.Bundle usageIs a data storage tool Bundle (String key, value). key can only be of the String type, value can be of other types.Message Processing Methods in new threadsLogoff cyclically retrieves messages from the queue. When there is no message in the queue, the thread will sleep.

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.