Android 4.0 main thread access network problems, android4.0

Source: Internet
Author: User

Android 4.0 main thread access network problems, android4.0

If the number of requests to access the network in the main thread is less than 4.0, ANR will be reported if the number of requests exceeds 6 S, which will lead to a problem. If the network is slow or the requested data is too large, the interface will be choppy, resulting in poor interface sensitivity. Therefore, network requests are generally not allowed in the main thread. google made adjustments at 4.0. Generally, when requesting the network in the main thread, an error will be reported, in this way, our programmers have to subscribe the thread to go to the network. If 4.0 is used to operate the network in the main thread, the following error message is returned:

<Span style = "color: # ff6666;"> 10-19 12:14:44. 656: E/AndroidRuntime (30444): Caused by: android. OS. NetworkOnMainThreadException </span>





Android Development Network Problems

When the main thread accesses the network, this error will be reported after Android 4.0. In fact, it is not recommended to access the network in the main thread, which will cause the interface to be not smooth. You should open another thread to access the network, after obtaining the data, return the result to the main thread.

For android webservice connection

I haven't tried either of them. It's easy for android to connect to web service. After android 4.0, the main thread will not allow access to the network. You can write a new thread to solve this problem.
Let's take a look at this example.
Www.cnblogs.com/..6.html

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.