Unable to load a ListPreference Dialog in a PreferenceScreen held by an ActivityGroup

StackOverflow https://stackoverflow.com/questions/10494026

  •  06-06-2021
  •  | 
  •  

سؤال

I have an ActivityGroup implemented on a certain tab. One of the screens in this ActivityGroup is a PreferenceScreen and consists of a ListPreference in it.

On clicking the ListPreference an exception is thrown and it fails to load the dialog. Here is the full stack trace of the exception:-

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)

I also tried implementing a DialogPreference instead of a ListPreference but it still crashes in the same way.

It worked well before adding the Activity to an ActivityGroup.

هل كانت مفيدة؟

المحلول

Resolved this problem by setting the parent's context to the listpreference.

Thanks.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top