Skip to content

Instantly share code, notes, and snippets.

@shallowlong
Last active January 2, 2016 15:09
Show Gist options
  • Save shallowlong/8321616 to your computer and use it in GitHub Desktop.
Save shallowlong/8321616 to your computer and use it in GitHub Desktop.
Code is shared over the internet. Save the code snippet for activating the strict mode in Android
// Strict Mode is very helpful to the developers to track any of the policy we set, like the disk operation or the database operation, this will help the developer to track the app, the result is to popup an window showing the StritMode message when the app avoid the policies
// if we want to enable some policy in some place
// we can temporarily enable some policy from the existing
// StrictMode
// like the following way:
// StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
// // save the current one policy
// StrictMode.setThreadPolicy(new
// StrctMode.ThreadPolicy.Builder(old).permitDiskWrites().builder());
// doSomethingCorrespondingToTheWriteToTheDisk();
// StrictMode.setThreadPolicy(old); // set back
android.os.StrictMode
private static final boolean DEVELOPER_MODE = true;
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectAll().penaltyLog().penaltyDialog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectAll().penaltyLog().build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment