W/System.err: Strictmode Vmpolicy Violation with POLICY_DEATH; Shutting down

Asked

Viewed 72 times

0

When repeatedly opening an Activity the following error occurs:

E/StrictMode: class br.com.teccity.cardapiosduchef.empresa.EmpresaActivity; instances=2; limit=1
              android.os.StrictMode$InstanceCountViolation: class br.com.teccity.cardapiosduchef.empresa.EmpresaActivity; instances=2; limit=1
                  at android.os.StrictMode.setClassInstanceLimit(StrictMode.java:1)
W/System.err: StrictMode VmPolicy violation with POLICY_DEATH; shutting down.

Looking for a solution through the internet forums, I found the following example:

@Override
protected void onCreate(Bundle savedInstanceState) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectCustomSlowCalls() // API level 11, to use with StrictMode.noteSlowCode
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .penaltyLog()
            .penaltyFlashScreen() // API level 11
            .build());

    try {
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects() // API level 11
                .setClassInstanceLimit(Class.forName("com.apress.proandroid.SomeClass"), 100)
                .penaltyLog()
                .build());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    super.onCreate(savedInstanceState);

But it didn’t solve the problem either.

  • Everything points to a memory leak(memory Leak) caused by this Activity.

  • Could you tell me how I can identify what this leak would be?

  • You have to add the Activity code to the question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.