Attention:
(1) The main thread is not able to do time-consuming operations, network requests are time-consuming operations need to be put into sub-threading.
(2) The child thread cannot update the contents of the control (update UI). So there is a contradiction, the solution is to use handler (processing message mechanism).
Handler: How message mechanisms are written (important)
Steps to use handler:
1. Create a handler in the main thread
Private New Handler () { publicvoid handlemessage (android.os.Message msg) { };} ;
2. Handlermessage method for overriding handler
3. Create a Message object in the child thread to bind the obtained data to the MSG
New Message (); // Another way: Message msg = Messge.obtain; Msg.obj = result;
4. The handler object in the main thread sends a message to the main thread in a child thread
Handler.sendmessage (msg);
5. The Handlermessage method in the main thread accepts data from a child thread and can do an update of the UI.
Android's network programming