title: StrictMode disk read violation on empty activity's setContentView
body: <p>I've recently tried to use StrictMode but got a weird violation, so I tried setting up a <strong>new</strong> 'Empty Activity' project (in <code>Android Studio</code>) and added an Application class as follows (as described in <a href="https://developer.android.com/reference/android/os/StrictMode" rel="noreferrer">here</a>):  </p>
  
  <pre><code>public class TestApplication extends Application {
  
      @Override
      public void onCreate() {
          setStrictMode();
          super.onCreate();
  
      }
  
      private void setStrictMode() {
          if (BuildConfig.DEBUG) {
              StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                      .detectAll()
                      .penaltyLog()
                      .build());
              StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                      .detectLeakedSqlLiteObjects()
                      .detectLeakedClosableObjects()
                      .penaltyLog()
                      .penaltyDeath()
                      .build());
          }
      }
  }
  </code></pre>
  
  <p>I have the same problem in this empty project:<br>
  <code>StrictMode policy violation; ~duration=165 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=65599 violation=2</code></p>
  
  <p>Stack:</p>
  
  <pre><code>at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1440)
  at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:241)
  at java.io.File.isDirectory(File.java:837)
  at dalvik.system.DexPathList$Element.toString(DexPathList.java:634)
  at java.lang.String.valueOf(String.java:2827)
  at java.util.Arrays.toString(Arrays.java:4511)
  at dalvik.system.DexPathList.toString(DexPathList.java:194)
  at java.lang.String.valueOf(String.java:2827)
  at java.lang.StringBuilder.append(StringBuilder.java:132)
  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:126)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
  at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:1933)
  at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2586)
  at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2659)
  at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2067)
  at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:374)
  at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
  at com.test.testapp.MainActivity.onCreate(MainActivity.java:11)
  at android.app.Activity.performCreate(Activity.java:7009)
  at android.app.Activity.performCreate(Activity.java:7000)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
  at android.app.ActivityThread.-wrap11(Unknown Source:0)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
  at android.os.Handler.dispatchMessage(Handler.java:106)
  at android.os.Looper.loop(Looper.java:164)
  at android.app.ActivityThread.main(ActivityThread.java:6494)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  </code></pre>
  
  <p><strong>The question(s):</strong><br>
  Is this a configuration problem?<br>
  If not, can I make StrictMode ignore specific method calls (it happens on a <code>layoutInflater.inflate</code> call as well on the original project)?</p>
  
  <hr>
  
  <p><strong>Edit</strong> (add configuration):<br>
  Android Studio version: 3.1.3<br>
  minSdkVersion 21<br>
  targetSdkVersion 27<br>
  appcompat-v7:27.1.1<br>
  Device: Nexus 6p</p>
  
  <p><strong>Edit2</strong> (solution):<br>
  I realized that the solution by <a href="https://stackoverflow.com/users/115145/commonsware">CommonsWare</a> is somewhat hidden in his comment below, so: it was the <a href="https://stackoverflow.com/a/35169716/4759619">instant run enabled</a> that caused my problem.</p>