Android handler (2)

Source: Internet
Author: User

Note: We create a handler object to call the POST method, and then pass it into a runnable object. This method does not create a new thread.

Handlerthread and logoff:Handlerthread is a subclass of thread.

The following is the application framework:

1. First create the handlerthread object

2. enable the new thread by using the start method of the handlerthread object

3. Create a class to inherit handler and call the constructor containing logoff.

Public class myhandler extends handler {

 Public myhandler (low.logoff ){
Super (logoff );
}

Public void handlermessage (Message MSG ){}

}

4. Create a myhandler instance and pass in the getlooper of the handlerthread instance as the parameter.

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

Message message = handler. obtainmessage ();

// The target is the handler object that obtains the message object.

Message. sendtotarget ();

 

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.