Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why setting up strictMode not working in Application without handler

Tags:

android

When I want to set strictMode in Application without handler - no effects in Activities.

This code is working:

public class MyApp extends Appliction {

    @Override
    public void onCreate() {
    super.onCreate();

    new android.os.Handler().post(new Runnable() {

        @Override
        public void run() {
            setup_strict_mode();
        }
    });

    } 
}

This code is NOT working (no strict mode enabled in Activities)

public class MyApp extends Appliction {

    @Override
    public void onCreate() {
    super.onCreate();

    setup_strict_mode();

    }

}

Here is setup_strict_mode:

       StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyDeath().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog().build());

Though onCreate is running in UI thead, so why this is happening?

like image 856
Dominik Suszczewicz Avatar asked Jun 02 '14 14:06

Dominik Suszczewicz


People also ask

How do I turn on strict mode on Android?

Go to Settings > Developer options. Tap Advanced > Strict mode enabled.

What is StrictMode policy violation?

StrictMode (android. os. StrictMode) class can be used to enable and enforce various policies that can be checked for and reported upon. This can be a StrictMode violation in executing a disk write violation that occurs when you are performing disk writes on the main UI thread.


1 Answers

Ok guys, I have found the solution. Its a bug described he

http://code.google.com/p/android/issues/detail?id=35298

like image 150
Dominik Suszczewicz Avatar answered Oct 21 '22 10:10

Dominik Suszczewicz