android.os.NetworkOnMainThreadException

来源:互联网 发布:吃鸡网络延迟检测 编辑:程序博客网 时间:2024/06/09 22:40

 错误原因:

 4.0的系统,在主线程中调用了http相关的方法。



StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.

StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users.


参考:

http://developer.android.com/reference/android/os/StrictMode.html


解决办法:

如果是在Activity中,可以使用AsyncTask

http://blog.csdn.net/icephone/article/details/6633024

Service中使用Thread和Handler。


PS:待完善。



原创粉丝点击