Crash in ListPreference during rotation
See original GitHub issueHello. If you rotate device 2 times with the open dialog then occurs crash:
java.lang.IllegalStateException: Failure saving state: ListPreferenceDialogFragmentCompat{9d3f3e08 #1 android.support.v7.preference.PreferenceFragment.DIALOG} has target not in fragment manager: SettingsFragment{9d3f3c08}
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1935)
at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:134)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:568)
at android.support.v7.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:511)
at android.app.Activity.performSaveInstanceState(Activity.java:1153)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1223)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3712)
at android.app.ActivityThread.access$900(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Crash on rotation when PreferenceScreen has key
I have preference screen with key so I can show/hide it based on debug state. Kotlin. caller.findPreference("debug_key_screen").isVisible = ...
Read more >Prevent crash on screen rotation when showing panic app selector ...
Fixes this crash: Caused by: java.lang.IllegalStateException: ListPreference requires an entries array and an entryValues array. at android.preference.
Read more >Androidx.Preference.Listpreference Dialog Crashes - ADocLib
When I click on Preferred Audioplayer then rotate the screen to landscape view the app crashes and exit.How to reproduce.Download the app from...
Read more >Preference components and attributes - Android Developers
This topic describes some of the most commonly-used Preference components and attributes used when building a settings screen.
Read more >[MOD]270/360 Rotation mod 2.1 (Now fixed and 100% working ...
Builds fine just crashes as rotation settings are incomplete in the 3rd smali ... AccelerometerMode uses HtcListPreference not normal android ListPreference ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I see the problem and is not related to this library nor any other libs. The problem is the way you create / use your
StorageSettingsFragment
. You probably use the fragment adder in a similar manner in yourActivity
:The problem with this is that when you rotate your phone, a new fragment gets created every time which replaces the old one. This won’t crash until you have a child fragment of that fragment (in this case it’s
ListPreferenceDialogFragmentCompat
) which has the old fragment as a target set.To solve the problem, you just have to check whether it’s the first time
onCreate(...)
is called. It’s pretty simple with the received argument ofsavedInstanceState
. If it’snull
, it’s the first time. Nice, huh? In your case, the actual fix looks like this:Thanks for the tip. I’ll try to do either.