java.lang.IllegalStateException:指定的消息队列同步屏障令牌尚未发布或已被删除

时间:2018-09-30 11:14:45

标签: android runnable illegalstateexception android-handler android-looper

我正在尝试访问一些SharedPreferences并在活动的Dialog方法内的mainUiThread上填充onCreate()

这是我的onCreate()方法代码中的一些:

@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
        }
    });
}

我为什么这样做? 我注意到,我用来访问SharedPreferences然后膨胀Dialog的代码给主线程带来了沉重的负担,因此我将其放在Handler中。我开始在Crashlytics上找到它:

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)

有什么主意吗?

0 个答案:

没有答案