Google banned network access in the main thread after the 4.0 system because:
The main thread is the response to the UI, and if the main thread makes network access for more than 5 seconds, it will cause a forced shutdown.
So this time-consuming operation cannot be placed in the main thread. is placed in a sub-thread, and the thread is not able to change the UI of the main thread,
Therefore, it leads to the handler, which is defined in the main thread, handler, and used in sub-threads.
The wording of the message mechanism
[1] ANR Application not response application unresponsive main thread (UI thread)
[2] If a time-consuming operation in the main thread (such as connecting the network copy large Data) Threa.sleep ()
[3] Avoid the ANR can put the time-consuming operation into the child thread itself in the creation of a thread
[4] After 4.0, Google forced the connection network can not be accessed in the main thread
Android.os.NetworkOnMainThreadException
[5] Only the main thread (UI thread) can update the UI
Android.view.viewrootimpl$calledfromwrongthreadexception:only
The original tread that created a view hierachy can touch its view.
[6] Information mechanism
Workaround: Open a child thread
New Thread () { @Override publicvoid run () { // TODO auto-generated method Stub // inside Write network connection What's the process of Super. Run ( ); }; }. Start ();
Android.os.NetworkOnMainThreadException after 4.0 Google forced the connection network cannot be accessed on the main thread