安卓請求網絡錯誤 直接在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中 加上上面這一段便可取消限制java

但最好使用子線程請求 經過消息機制更新ui 避免ui無響應網絡

相關文章
相關標籤/搜索