更新时间:2023-02-26 13:52:39
尝试使用以下mainactivityactivity的setContentView()内低于code,以避免networkOnmainThread例外。
Try using the below code inside your mainactivityactivity below setContentView() to avoid networkOnmainThread exception..
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
不过,在做内部使用的AsyncTask不阻塞主线程后台线程操作重将是巨大的!
But, doing heavy operation inside background thread using AsyncTask without blocking main thread would be great!
和还提到此链接...
And also refer this link...