Handler ------ notes

Source: Internet
Author: User

I. handler is a class provided by the Android operating system.

A queue is a (first-in-first-out) data structure.

2. runable updatethread = new runable () {}; // write the operation to be executed in the run method of the thread object

Handler handler = new handler (); // create a thread object

Handler. Post (updatethread); // call the post method of handler and add the thread object of the thread to be executed to the queue.

Handler. postdelayed (updatethread, 3000); // execute the postdelayed or POST method inside the run Method

3. Bar. setvisibility (view. Visible); // you can specify that the progress bar is visible.

Runnable updatethread = new runable () {}// the Thread class is declared using an anonymous internal class.

Message MSG = updatebarhandler. obtainmessage (); // get a message object. The message class is provided by the Android operating system.

MSG. arg1 = I; // set the arg1 parameter of the MSG object to I and use the two member variables arg1 and agr2 to transmit messages. The advantage is that the system consumes less

Thread. Sleep (1000); // sets the current thread to sleep for one second.

Updatabarhandler. sendmessage (MSG); // Add the MSG object to the Message Queue

4. system. Out. println (''activity ------> "+ thread. currentthread (). GETID ());

System. Out. println (''activityname ------>" + thread. currentthread (). getname ());

Handlerthread = new handlerthread ("handler_thread"); // generates a handlerthread object and implements the function of using logoff to process message queues. This class is used by Android applications.ProgramFramework provision

Handlerthread. Start (); // before using the getlooper () method of handlerthread, you must call start () of this class ()

Myhandler = new myhandler (handlerthread. getlooper ());

Message MSG = myhandler. obtainmessage (); // send MSG to the target object. The so-called target object is the handler object that generates the MSG object.

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.