Mainactivity such as the following:Package Cc.c;import Android.app.activity;import Android.os.bundle;import android.os.handler;import Android.os.looper;import Android.os.message;import android.widget.textview;/** * Demo Description: * * Demo sample process such as the following: * 1 child threads to the child thread itself Send Message * 2 after receiving 1 message, the child thread sends a message to the main thread * 3 receives a 2 message, the main thread sends a message to the child thread *
Handler's understanding and use 1. Handler's understanding and use
Directory:
Basic knowledge:
1. Android process and thread model
2. Main Android UI thread (or thread security issues)
Knowledge points:
Handler Introduction
Handler Method 1: The subthread processes the transaction (working in the background). After the task is finished, the subthread sends a message through
A summary of Handler usage and a summary of Handler usage
* *********************************** MHandler. postDelayed (image polling) and mHandler. post (with the new UI) ************************************
Activity_main.xml
MainActivity
Package com. example. handlerdemo; import android. r. mipmap; import android. app. activity; import android. OS. bundle; import android. OS.
From the source code analysis Handler mechanism, the source code handler Mechanism
In Android, to update the ui, We must update the ui in the main thread. When the main thread is blocked for more than 5 seconds, an anr exception occurs, will cause program crash. Therefore, some time-consuming operations must be placed in the Child thread, but the ui update operations cannot be performed in the Child thread
Android asynchronously updates UI-thread pool-Future-Handler instance analysis, ui-future-handlerAndroid asynchronously updates UI-thread pool-Future-Handler instance analysis
During Android development, time-consuming tasks are processed and refreshed in sub-threads. the following two questions are raised by most developers:
1. Data often needs to be read and updated, which is time-consuming. You need to r
[Kernel Research] processor _ Handler, kernel research _ handler
Although MessageQueue provides direct read/write function interfaces, it generally does not directly read/write message queues to programmers. The Handler get type is exactly Handler.
/** * Run the message queue in this thread. Be sure to call
Use Handler to update the UI in the Child thread and the handler thread to update the ui
Android requires that you only update the UI in the main thread. If you update the UI in the Child thread, the following error is prompted: only the original thread that created a view hierachy can touch its view (Only the original thread can create a view level to touch its view ).
The reason why the UI can only be upd
Memory leak analysis when using handlerIn Android, there are often some operations on the main thread after processing an asynchronous task, so we might use handler, the following are common uses of handler:publicclass MainActivity extends AppCompatActivity { privatenew Handler() { @Override publicvoidhandleMessage(Message msg) { //TODO } };}But when we use this, we see
Android thread processing Handler and android thread handler
The previous article has briefly introduced how to use Handler. In this article, we will discuss the advanced use of Handler. in the previous article, we just updated the UI, in this article, we will discuss how to send data from sub-threads to the main threa
Android Development notes-Summary of Handler (I) and Android handler
Next, I wrote "android Development notes-about the use of AsyncTask". Today, I am going to talk about another Asynchronous Operation Handler in Android development.
Today, I plan to explain some basic definitions and usage of Handler.
Take a download
Handler and handler
This section describes how to use Handler and related knowledge. Before learning about Handler, let's take a look at these questions.
What is Handler?
There are several typical methods for updating the UI of a sub-thread. What are these methods es
/131228/1123306304-0.jpg "title =" not touch. jpg "/>
After triggering:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1123301639-1.jpg "title =" after the touch. jpg "/>
When users use this experience, it can be imagined that it will be very painful...
Someone will ask why there is a mechanism like ANR.
In fact, all the UI display in the android system is executed in the main thread. If there is time-consuming operation in the thread, other UI components in the thre
If you instantiate without parameters: Handler handler=new Handler (), then this will default to the Looper object of the current thread.In general, if your handler is to be used to refresh the UI, it needs to run under the main thread.Case1 to refresh Ui,handler to use the
What can I get?
After reading all the articles in the "HTTP Handler" series, you can-Easily create your own custom HTTP handler-Share the Session between your HTTP handler and the Web Handler-Allows dynamically generated images to be directly displayed on the web page without the need for temporary file transfer.-Send
Understand the handler mechanism and handler Mechanism
I,LogoffClass
First of all, you know that a class, The logoff class, as its name implies, is the meaning of the loop operator, so the existence of the logoff class is to make an ordinary thread become a thread that will be executed cyclically, we can understand it as a long-lived medicine.
The general Thread class can be cyclically executed by executin
Handler, HandlerHandler's Basic ConceptsHandler provides an asynchronous processing mechanism. There are two queues: one is the queue that puts the thread into, and the other is the message queue. Activity is a thread and download is another thread.Handler basic usageAdd to message queue immediately: post (Runnable object reference), remove from Message Queue: removeCallback (Runnable object reference) 1. create a
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.