title: Android sharedPreferences.commit unable to read file
body: <p>I have a Broadcast Receiver that clears the shared preferences file and then commits. My app runs into ANR since the clear works but the commit is not able to read the file for some reason</p>
  <p>The broadcast receiver also times out..</p>
  <p>I am unable to understand what the stack trace means. Can someone help me understand what happened here? And is there a way to avoid this?</p>
  <p>Here is the stack trace :</p>
  <pre><code>&quot;main&quot; prio=5 tid=1 Native
    | group=&quot;main&quot; sCount=1 dsCount=0 obj=0x7599a000 self=0xb84a5e98
    | sysTid=15259 nice=0 cgrp=bg_non_interactive sched=0/0 handle=0xb6f1d000
    | state=S schedstat=( 137176743 6798788178 493 ) utm=4 stm=9 core=0 HZ=100
    | stack=0xbe0d0000-0xbe0d2000 stackSize=8MB
    | held mutexes=
    kernel: (couldn't read /proc/self/task/15259/stack)
    native: #00 pc 00012ab0  /system/lib/libc.so (syscall+28)
    native: #01 pc 000a98af  /system/lib/libart.so (_ZN3art17ConditionVariable4WaitEPNS_6ThreadE+82)
    native: #02 pc 001c1529  /system/lib/libart.so (_ZN3art3JNI17GetStringUTFCharsEP7_JNIEnvP8_jstringPh+672)
    native: #03 pc 000139eb  /system/lib/libjavacore.so (???)
    native: #04 pc 00020dfd  /system/lib/libjavacore.so (???)
    native: #05 pc 002859e3  /system/framework/arm/boot.oat (Java_libcore_io_Posix_open__Ljava_lang_String_2II+118)
    at libcore.io.Posix.open(Native method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
    at libcore.io.IoBridge.open(IoBridge.java:442)
    at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:89)
    at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:74)
    at android.app.SharedPreferencesImpl.createFileOutputStream(SharedPreferencesImpl.java:578)
    at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:631)
    at android.app.SharedPreferencesImpl.access$900(SharedPreferencesImpl.java:53)
    at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:532)
    - locked &lt;@addr=0x22d600f0&gt; (a java.lang.Object)
    at android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:551)
    at android.app.SharedPreferencesImpl.access$100(SharedPreferencesImpl.java:53)
    at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:473)
  </code></pre>
  <p>Here is the sample code :</p>
  <pre><code>public class AppBroadcastReceiver extends BroadcastReceiver {
  
     @Override
      public void onReceive(Context context, Intent intent) {
  
         SharedPreferences mSharedPre = context.getSharedPreferences(&quot;sharedPrefFile&quot;, Context.MODE_PRIVATE);
         SharedPreferences.Editor sharedPrefEditor = mSharedPre.edit();
         sharedPrefEditor.clear();
  
         sharedPrefEditor.commit();
  
      }
  
  }
  </code></pre>