[Reprinted] Android asynchronous processing series of articles, android asynchronous

Source: Internet
Author: User

[Reprinted] Android asynchronous processing series of articles, android asynchronous

This blog address: http://blog.csdn.net/mylzc/article/details/6777767 reprint please indicate the source.

To provide users with a good interactive experience, you need to put heavy tasks (I/O, network connections, etc.) into other threads for asynchronous execution during Android application development, achieve the effect of not blocking the UI.

This series of articles introduces the implementation method and underlying system implementation principle of Android asynchronous processing in a simple way.

Android asynchronous processing 1: Using Thread + Handler to implement non-UI Thread to update the UI interface (Getting Started)

This section describes how to use Thread + Handler to update a message from a non-UI Thread to a UI Thread.

Android asynchronous processing 2: Use AsyncTask to asynchronously update the UI (Getting Started)

Describes how to use AsyncTask to asynchronously update the UI

Android asynchronous processing 3: Handler + logoff + MessageQueue (advanced)

Tracking System Code and introducing the implementation principle of Thread + Handler

Android asynchronous processing 4: implementation principle of AsyncTask (advanced)

Tracks system code and introduces the implementation principle of the underlying AsyncTask system.


Differences between asynchronous processing in Java and asynchronous processing in Android

A new thread is used for processing.
 
In Android, what is asynchronous execution?

Let me explain the asynchronous usage for you,
If you are not a developer, Jump directly to the third, the difference between the asynchronous concept and synchronization:
1. Write an internal class in your Activity:
Private class TestAsyncTask extends AsyncTask <String, Void, Boolean>
{
@ Override
Protected void onPreExecute ()
{
// This is the first execution.
}

@ Override
Protected Boolean doInBackground (String... params)
{
// This is the execution in the background, that is, it automatically runs in another thread without affecting what you are doing now.
}

@ Override
Protected void onPostExecute (Boolean result)
{
If (result)
{
// After the execution is completed in the background, it will use Result to notify you that it is the execution.
}
Else
{
// It is best to judge the result and write an else to determine whether something is going wrong in the background.
}
}
}

2. Start this Asynchronous Method in onCreate. the startup code is as follows:
New testasynctask(cmd.exe cute ("");

Iii. Differences between Asynchronization and Synchronization
The advantage of Asynchronization is to throw some things, especially time-consuming things, to the background for running. The doInBackground program can continue to do its own things to prevent the program from failing to respond.
Synchronous execution means that the program will be executed from the beginning to the end with no downtime and the program will not continue, sometimes it will cause a loss of response.

I am engaged in development. My code can be used if you paste it directly. It's hard to type and paste code ~~ Hope to adopt it. You are also welcome to ask

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.