Interaction and collaboration between threads
Although the thread and thread share the memory space, that is, they can access the heap space of the process, but the thread has its own stack, method calls running in a thread are all in the thread's
Android UI operations are not thread-safe, and only the main thread can operate the UI. At the same time, the main thread has a certain time limit on UI operations (up to 5 seconds ). To perform some time-consuming operations (such as downloading
The Hidden Trap of AsynctaskLet's take a look at an example
This example is very simple, it shows the extreme use of asynctask, very strange.
Copy Code code as follows:
public class Asynctasktrapactivity extends activity {
Private
A few key concepts1, MessageQueue: is a data structure, see the name of righteousness, is a message queue, the place to store messages. Each thread can have a maximum of one MessageQueue data structure.When a thread is created, its MessageQueue is
Message, messagequeue, logoff, and handler in Android + Example 1. Several key concepts
1. messagequeue: a data structure. It is a message queue where messages are stored. Each thread can have at most one messagequeue data structure.
Messagequeue
The hidden trap of asynctask first looks at an instance.
This example is very simple. It is strange to show an extreme usage of asynctask.
public class AsyncTaskTrapActivity extends Activity { private SimpleAsyncTask asynctask; private Looper
Android Message, MessageQueue, logoff, Handler (with example), messagequeueloading
I. Several key concepts
1. MessageQueue: a data structure. It is a message queue where messages are stored. Each thread can have at most one MessageQueue data
The role of handler is to send a message and handle the message sent by Message,handler is actually sent to its own object for processing, so who is sent who is handling, but this absolutely makes sense, So that we can move the processing of the
Overview* Message: Messages. Messages can contain simple data, object and bundle, and can contain a runnable (which can actually be considered a callback). * MessageQueue: Message Queuing for looper threads to consume messages. * Looper: Used to
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.