November 10, 2014 Android Learning Summary

Source: Internet
Author: User

One, thread


1. UI thread

A, Handler Handler = new Handler ();

Runnable Runnable = new Runnable () {

public void Run () {

}

};

Handler.post (runnable);


B, Handler Handler = new Handler () {

public void Handlermessage (Message msg) {

}

};

Handler.sendmessage ();


Second, new thread

A, thread thread = new Thread (Runnable () {

Public void Run () {

       }

). Start ();

  

B, Handlerthread handlerthread = new Handlerthread ("Handler_thread");

Handlerthread.start ();

Mhandler Mhandler = new Handler (Handlerthread.getlooper ());

Message msg = Hangdler.obtainmessage ();

Msg.sendtotarget;

Class Mhandler extends handler{

Handlemessage

      }


C,Asynctask

Steps:

① Instantiation of Asynctask:

Instantiate Asynctask then pass task.exec (Pamas); Pass in the parameter, this parameter list is dynamic, can be one can also make multiple, length variable.

Asynctask, the first parameter is passed in the method Doinbackground (params), the second parameter is the value of the data update, and the third is the result of processing the return of the transaction.

②onpreexecute Method:

This method has no parameters and no return value, so you can do some reminders in this method. Like show a dialog, or play a toast and tell the user to start the download.

③doinbackground (params) method:

Enter the ASYNCTASK internal structure, first will execute the Reslut doinbackground (params) method, this method will handle the time consuming transaction, exec () parameters will be passed into this method to do parameters, and the return value will be as OnPostExecute () The parameters. If you want to update your progress, you need to execute the publicprogress () method.

④onprogressupdate (values) method:

The parameter of this method must execute the Publicprogress () method in the Doinbackground () method, this method will pass the parameter into the Onprogressupdate () method, then can do some UI update display in this method, For example, the value of the progress bar can be changed dynamically through this values value.

⑤onpostexecute (Result) method:

Here is the way the transaction is completed, and the results of the Doinbackground method execution will be uploaded here, if the method returns data. The UI can be handled in this way, and the processed data can be displayed on the UI. than a piece of text Ah, everything you want results.




November 10, 2014 Android Learning Summary

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.