我的应用程序在Android 2.3及更低版本上成功运行,但它在android 4.0和4.2中给出了响应null。在google上搜索后,我发现HoneyComb和Ice Cream Sandwich对于滥用UI线程更为严格。
ICS和HoneyComb不允许您在UI线程上执行的其他操作的一些示例是:
Opening a Socket connection (i.e. new Socket()).
HTTP requests (i.e. HTTPClient and HTTPUrlConnection).
Attempting to connect to a remote MySQL database.
Downloading a file (i.e. Downloader.downloadFile()).
If you are attempting to perform any of these operations on the UI thread, you must wrap them in a worker thread. The easiest way to do this is to use of an AsyncTask, which allows you to perform asynchronous work on your user interface. An AsyncTask will perform the blocking operations in a worker thread and will publish the results on the UI thread, without requiring you to handle threads and/or handlers yourself.
这意味着我必须更改旧代码吗?我在我的项目中调用HTTP请求超过50次。所以我必须在每个类中手动更改它,因此它将在HTTP请求上运行吗?
任何建议都将受到赞赏。