4.0后主线程执行http请求问题

前面提到过Adnroid4.0以后在主线程中执行http请求时要加两行代码才行

StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

其实还有一种方法,就是写个子线程,在子线程访问就行。

原文地址:https://www.cnblogs.com/wangyuehome/p/2956071.html