on the message first queue), a processing the first message when there are 1 tickets, so a out of a ticket, When processing the second message, there was no ticket, so it said with schadenfreude: "There is no ticket, that cool to stay."Because a is in the process, so two messages will not be processed at the same time, there will not be two times to check that there is a ticket left.(2) Internal mechanism:First, then look at the code:(Note starting from handler)HD Feed Code:(1) Establishment of
Off topic:To say a little ashamed, the initial understanding of these three is actually in the back of the test. It wasn't long before I touched Android, and the books I learned were the "crazy Android handouts" that were better for getting started, of course, when you were learning about the handler part of the book, there were some simple examples. Later in the work need to use this MessageQueue time only to begin to really ponder the three links. I
Original address: Http://www.cnblogs.com/codingmyworld/archive/2011/09/12/2174255.html#!commentsAs a junior preparatory programmer, one of my great pleasures in learning Android is that I can learn the design ideas of Google Daniel through the source code. Android source contains a large number of design patterns, in addition, the Android SDK also carefully designed for us a variety of helper classes, for me as eager as the level of the people who want to be advanced, it is worth reading. This i
This article is very good, simple, the key is a junior students to analyze their own experience. This is the reason why I like this article. Please see the text below:
As a junior preparatory programmer, I learn the fun of Android is to learn from the source code Google Daniel's design ideas. The Android SDK has a lot of design patterns in it, and in addition to that, it has designed a variety of helper classes for us, and it's too much to read for someone like me who wants to get to the next l
We know that wirelessly's UI thread is not thread-safe, we can't take time out in the UI thread, and it's usually our practice to turn on a sub-thread to handle time-consuming operations in a child thread, but Android does not allow UI updates to be performed on child threads, and usually we do that with the handler mechanism. , that is, when the time-consuming operation in the child thread completes, the message is sent to the main thread in the child thread through handler, and the received me
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 not created automatically. A Looper object is typically used to manage the MessageQueue of the thread. When the main thread is created, it creates aA default Looper
message system and simple principle.Let's learn the fundamentals of the messaging system.The basic principle and composition of the two-message systemThe establishment of a generic message system model roughly consists of the following parts:L Message PrototypeL Message QueuingL Send a messageL message loopL Message AcquisitionL Message DistributionL Message ProcessingThe approximate model diagram is as follows: The message system model typically includes the above seven parts (message proto
Analysis of the above article, the basic understanding of the implementation of the principle of handler, by hot iron, here we use the handler principle, in the sub-thread to create a handler and LooperMaybe a lot of interviews ask, can I get a new handler in the sub-thread?The answer is yes, but since the main thread system default in Activitythread will help us create good one looper and messagqueue, we don't need to manually create(manual creation
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 Simpleasynctask Asynctask;
Private Looper Mylooper;
Private TextView status;
@Override
public void OnCreate (Bundle icicle) {
Super.oncreate (Icicle);
Asynctask = null;
New Thread (New Runnable () {
@O
Message: messages, which contain message IDs, message processing objects, and processed data, are unified by MessageQueue, and eventually handled by handler.
Handler: Processor, responsible for message delivery and processing. When using handler, you need to implement the Handlemessage (Message msg) method to handle a particular message, such as updating the UI.
MessageQueue: Message Queuing, which is used to store messages sent by handler and executed in accordance with FIFO rules. Of course, s
first, take a look at the use of the process1. Using handler instances in child threads /*********** Child Threads Use Handler instance *********/ private class Looperthread extends thread {public Handler Handler; @Override public Void Run () { looper.prepare (); Handler = new Handler () { @Override public void Handlemessage (Message msg) { } };
Understanding LooperLooper is used to add a message queue (MessageQueue) to a thread, and to loop through a tool that, when there is a message, evokes a thread to process the message until the thread is finished. Looper is not normally used because, for system components such as Activity,service, frameworks has initialized a thread (commonly known as a UI thread or main thread) with a looper in it and a mes
Android Threading message passing mechanism--looper,handler,messageBefore introducing these concepts, let's look at the context in which these mechanisms are introduced.For performance optimizations, Android UI operations are not thread-safe (if you don't know what thread safety is, you can read Here's a question: What if your Android program wants to download a picture on the Web (we don't consider using Android-provided components for the moment), a
A lot of people interviewed must have been asked, what is the relationship between Looper, Handler, and message in Android? The purpose of this blog is to introduce 3 relationships from the source point of view, and then give a conclusion that is easy to remember.1. Overview handler, Looper, and message all three concepts related to the Android asynchronous message processing thread. So what is the asynchro
IntroductionWhen we do Android development, we often need to implement the asynchronous loading of images/Web pages/other. In fact, to implement asynchronous loading, you need to implement inter-thread communication, while in Android, using Handler, Looper, and Message enables different threads to communicate and complete asynchronous tasks. Although Android has provided us with the Asynctask class to accomplish asynchronous tasks, there are many prob
Android's message processing has three core classes: Looper,handler and message. There's actually a message queue, but MQ is encapsulated in Looper, and we don't deal directly with MQ, so I don't use it as a core class. Here are the following:Thread of the magician LooperLooper literally means "circulator", which is designed to make a normal thread into a looper
Android's message processing has three core classes: Looper,handler and message. There's actually a message queue, but MQ is encapsulated in Looper, and we don't deal directly with MQ. Usually we use the most often is the message and handler, if the use of handlerthread or their own implementation of similar handlerthread may also be exposed to looper, and Messag
In the previous blog post, two typical instances of inter-thread communication based on the handler Looper mechanism in Android were given. In this paper, the basic principles of this mechanism are studied in depth. Personally think, learn Android programming the best teacher is the source code of Android, the following will be based on the Android-19 source for analysis, focusing on the analysis of ideas.To analyze the handler
Objective:The previous article is about bitmap and memory optimization technology, this article to everyone talk about handler.Handler is an important knowledge of the Android system, which is often asked in Android multithreaded interviews and is often used in real-world projects. Of course, more complex, more knowledge, involved in the class has thread, Looper, Message, MessageQueue.Android is multi-threaded, usually the user-related UI events in th
ThreadLocalBefore looking down, you need to know about Java's threadlocal class, you can refer to the blog: Decryption ThreadlocalLooper, Handler and MessageQueueLet's analyze the previous code and see what the relationship between Handle, Looper, and MessageQueue is in the handler mechanism.classWorkerthreadextendsThread {@Override Public voidrun () {Super. Run (); Looper.prepare (); Handler=NewHandler () {@Override Public voidhandlemessag
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.