安卓请求网络错误 直接在main Thread 进行网络操作出现maintreamexception

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

  ,从Honeycomb SDK3.0开始 谷歌禁止了直接在主线程请求网络在oncreate中 加上上面这一段即可取消限制

但最好使用子线程请求 通过消息机制更新ui 避免ui无响应

原文地址:https://www.cnblogs.com/ProDoctor/p/8016495.html