Method used to enable or disable the Strict Mode API, this API is really useful for developers to find applications errors or memory leaks, or long time lose writing to disk, etc. - Android android.os

Android examples for android.os:StrictMode

Description

Method used to enable or disable the Strict Mode API, this API is really useful for developers to find applications errors or memory leaks, or long time lose writing to disk, etc.

Demo Code


//package com.java2s;
import android.os.StrictMode;

public class Main {
    /**//www . j a v a 2 s . c o m
     * Method used to enable or disable the Strict Mode API, this API is really useful
     * for developers to find applications errors or memory leaks, or long time lose writing to disk, etc.
     *
     * @param enabled true or false, used to enable or disable the Strict Mode API
     */
    public static void enableStrictModeApi(boolean enabled) {
        if (enabled) {
            StrictMode
                    .setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                            .detectDiskReads().detectDiskWrites()
                            .detectNetwork() // or .detectAll() for all detectable problems
                            .penaltyLog().build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects().penaltyLog()
                    .penaltyDeath().build());
        }
    }
}

Related Tutorials