错误原因:
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.youkuaiyun.com/icephone/article/details/6633024
Service中使用Thread和Handler。
PS:待完善。
本文详细介绍了在Android 4.0系统中,如何通过AsyncTask和Thread & Handler在Service中进行网络操作,以避免在应用的主要线程上执行耗时操作,从而提升用户体验和应用程序的流畅性。通过使用StrictMode工具检测并警告开发者可能发生的错误行为,确保应用在多线程环境下正常运行。
1230

被折叠的 条评论
为什么被折叠?



