Permalink
Browse files

Simplified example with StrictMode.

  • Loading branch information...
1 parent 16b5c86 commit 6bd99e94cb735246c72a95703a5a29a54fbec1a3 @inazaruk committed Jul 16, 2012
Showing with 6 additions and 18 deletions.
  1. +6 −18 StrictModeJB/src/com/example/strictmodefix/App.java
@@ -4,7 +4,6 @@
import android.app.Application;
import android.os.Build;
import android.os.Handler;
-import android.os.Message;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import android.os.StrictMode.VmPolicy;
@@ -19,30 +18,19 @@ public void onCreate() {
super.onCreate();
}
- @TargetApi(16)
- private static class StrictModeHandler_v16 extends Handler {
- private static final int ENABLE_STRICT_MODE = 1;
-
- public void enableStrictModePostOnCreate() {
- sendMessageAtFrontOfQueue(this.obtainMessage(ENABLE_STRICT_MODE));
- }
-
- @Override
- public void handleMessage(Message msg) {
- if (msg.what == ENABLE_STRICT_MODE) {
- doEnableStrictMode();
- }
- }
- }
-
private static void enableStrictMode() {
if (Build.VERSION.SDK_INT >= 9) {
doEnableStrictMode();
}
if (Build.VERSION.SDK_INT >= 16) {
//restore strict mode after onCreate() returns.
- new StrictModeHandler_v16().enableStrictModePostOnCreate();
+ new Handler().postAtFrontOfQueue(new Runnable() {
+ @Override
+ public void run() {
+ doEnableStrictMode();
+ }
+ });
}
}

0 comments on commit 6bd99e9

Please sign in to comment.