我正在尝试访问一些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)
有什么主意吗?