无法在ActivityGroup持有的PreferenceScreen中加载ListPreference对话框

时间:2012-05-08 06:56:29

标签: android listpreference

我在某个标签上实施了ActivityGroup。此ActivityGroup中的一个屏幕是PreferenceScreen,其中包含ListPreference

单击ListPreference时会抛出异常,无法加载对话框。以下是异常的完整堆栈跟踪: -

05-08 12:05:31.545: E/AndroidRuntime(247): Uncaught handler: thread main exiting due to uncaught exception
05-08 12:05:31.585: E/AndroidRuntime(247):  android.view.WindowManager$BadTokenException: Unable to add window -- token    android.app.LocalActivityManager$LocalActivityRecord@44ec8ac8 is not valid; is your activity running?
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.view.ViewRoot.setView(ViewRoot.java:468)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.app.Dialog.show(Dialog.java:239)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.preference.DialogPreference.showDialog(DialogPreference.java:307)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.preference.DialogPreference.onClick(DialogPreference.java:265)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.preference.Preference.performClick(Preference.java:811)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.preference.PreferenceScreen.onItemClick(PreferenceScreen.java:190)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.widget.ListView.performItemClick(ListView.java:3285)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:1640)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.os.Handler.handleCallback(Handler.java:587)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.os.Looper.loop(Looper.java:123)
05-08 12:05:31.585: E/AndroidRuntime(247):  at android.app.ActivityThread.main(ActivityThread.java:4363)
05-08 12:05:31.585: E/AndroidRuntime(247):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 12:05:31.585: E/AndroidRuntime(247):  at java.lang.reflect.Method.invoke(Method.java:521)
05-08 12:05:31.585: E/AndroidRuntime(247):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-08 12:05:31.585: E/AndroidRuntime(247):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-08 12:05:31.585: E/AndroidRuntime(247):  at dalvik.system.NativeStart.main(Native Method)

我也试过实现一个DialogPreference而不是ListPreference,但它仍然以同样的方式崩溃。

在将Activity添加到ActivityGroup之前,它运作良好。

1 个答案:

答案 0 :(得分:1)

通过将父级的上下文设置为listpreference来解决此问题。

感谢。