在4.0之后android采用了嚴格模式:所以在你得activity創建的時候,在super.onCreate(savedInstanceState);后面加上這個
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectAll() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
轉載于:https://www.cnblogs.com/studynote/articles/5522774.html