我的应用程序在 android 2.3 及更低版本上成功运行,但它在 android 4.0 和 4.2 中给出了响应 null。在谷歌上搜索后,我知道 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 请求上运行?
任何建议将不胜感激。