title: java.lang.IllegalStateException: The specified message queue synchronization barrier token has not been posted or has already been removed
body: <p>I am trying to access some <code>SharedPreferences</code> and inflate a <code>Dialog</code> on the <code>mainUiThread</code> inside activity's <code>onCreate()</code> method:</p>
  
  <p>Here is some of my <code>onCreate()</code> method code:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      new Handler(Looper.getMainLooper()).post(new Runnable() {
  
          @Override
          public void run() {
              // Access shared Prefs, then inflate a dialog using the 
              // LayoutInflater class
          }
      });
  }
  </code></pre>
  
  <p><strong>Why I did this?</strong>
  I noticed that the code I'm using to access the <code>SharedPreferences</code> then inflating a <code>Dialog</code> makes heavy load on the main Thread so I put it inside a <code>Handler</code>. I started to get this on <code>Crashlytics</code>:</p>
  
  <pre><code>Fatal Exception: java.lang.IllegalStateException: The specified message queue synchronization  barrier token has not been posted or has already been removed.
     at android.os.MessageQueue.removeSyncBarrier(MessageQueue.java:289)
     at android.os.Looper.removeSyncBarrier(Looper.java:275)
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5996)
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
     at android.view.Choreographer.doFrame(Choreographer.java:544)
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
     at android.os.Handler.handleCallback(Handler.java:733)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:136)
     at android.os.HandlerThread.run(HandlerThread.java:61)
  </code></pre>
  
  <p>Any idea?</p>