A Brief Introduction to one of the android message systems
1. vc6.0 MFC message mechanism
Use pretranslatemessage to process messages;
2. The message processing mechanisms embedded in the activity include:
A. onkeydown;
B. Various Lister types, such as onkeydownlistener;
3. What work must be done through the message distribution processor?:
A. Scheduled event triggering;
B. asynchronous processing of cyclic events;
C. High time-consuming work;
4. the handler processes the messages in which thread:
By default, Handler accepts message loop instances in the current thread.
5. A message loop can be distributed and processed by multiple objects
A message loop can be distributed by multiple objects in the current thread for processing (in the UI thread, the system already has an activity to process, you can start several handler to process ...).
6. Minimum unit for CPU allocation for Android:
Thread
7. Relationship between handler and thread:
Handler is generally created in a thread, so handler and thread are bound to each other and correspond to each other one by one;
8. Relationship between runnable and thread:
Runnable is an interface and thread is a subclass of runnable. Therefore, both of them calculate a thread;
9. What is the role of thread (handlerthread?
As the name implies, handlerthread is a thread that can process message loops. It is a thread with logoff and can process message loops.
10. Handler runs in the UI thread and does not create a new thread:
The following code is available in the UI thread (main thread:
Mhandler = new handler ();
Mhandler. Post (New runnable (){
Void run (){
// Execute the code...
}
});
This thread is actually running within the UI thread, and there is no new thread.
11. The common method for creating a thread is:
Method 1:
Thread thread = new thread ();
Thread. Start ();
Method 2:
Handlerthread thread = new handlerthread ("string ");
Thread. Start ();
12. The main thread is the UI thread; 13. When to create the UI thread:
When an application is started, Android starts a main thread (that is, the UI thread)
14. main thread role:
The main thread distributes events for the UI controls on the management interface. For example, if you click a button, Android will distribute events to the button to respond to your operations.
15. What are the consequences of putting time-consuming work in the main thread?
If it is placed in the main thread, the interface will be suspended. If it has not been completed in five seconds, it will receive an error message "force close" from the Android system ".
16. What are time-consuming tasks:
A. Read data over the Internet;
B. Read a large local file;
C. hardware initialization;
17. How can I deal with time-consuming work?
Put these time-consuming operations in a child thread
18. The update UI can only be updated in the main thread;
Notes: The main thread is the UI thread;
19. Handler's role:
Handler:
1. Accept the message object passed by the sub-thread (which contains data );
Notes: subthreads are transmitted using the sedmessage () method;
2. Put these messages into the main thread queue,
3. Update the UI with the main thread .;
20. How to transmit data between handler and thread:
Handler and subthreads can transmit data through message objects.