Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListPreference Crash on theme change (Light to Dark or Vice versa) #213

Open
shgrg1712 opened this issue Aug 29, 2023 · 2 comments
Open

Comments

@shgrg1712
Copy link

shgrg1712 commented Aug 29, 2023

Hello All, I am using AOSP camera application where settings in camera application has been implemented using ListPreference. I am facing one issue which is crash on theme change (Dark to light or light to Dark).

One important - In AOSP camera application , there is no change on screen , when we change the theme. So make it compatible with theme change , we have changed the style of CameraSettingsActivity.
In this file change has been done
https://android.googlesource.com/platform/packages/apps/Camera2/+/refs/heads/main/res/values-v21/styles.xml#42
Changed the style parent

Old Code

<style name="Theme.CameraSettings" parent="@android:style/Theme.Material.Light.DarkActionBar"> true @color/main_color_global </style>

New Code

<style name="Theme.CameraSettings" parent="@android:style/Theme.DeviceDefault.DayNight"> true @color/main_color_global </style>

Same is done for Theme.Camera and Camera.ActionBar

This is code file
https://android.googlesource.com/platform/packages/apps/Camera2/+/refs/heads/main/src/com/android/camera/settings/CameraSettingsActivity.java

This is crash logs
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.android.camera2, PID: 3641
E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.camera2/com.android.camera.settings.CameraSettingsActivity}: java.lang.IllegalStateException: ListPreference requires an entries array and an entryValues array.
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3431)
E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5455)
E AndroidRuntime: at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5361)
E AndroidRuntime: at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7664)
E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

E AndroidRuntime: Caused by: java.lang.IllegalStateException: ListPreference requires an entries array and an entryValues array.
E AndroidRuntime: at android.preference.ListPreference.onPrepareDialogBuilder(ListPreference.java:258)
E AndroidRuntime: at android.preference.DialogPreference.showDialog(DialogPreference.java:331)
E AndroidRuntime: at android.preference.DialogPreference.onRestoreInstanceState(DialogPreference.java:514)
E AndroidRuntime: at android.preference.ListPreference.onRestoreInstanceState(ListPreference.java:324)
E AndroidRuntime: at android.preference.Preference.dispatchRestoreInstanceState(Preference.java:2066)
E AndroidRuntime: at android.preference.PreferenceGroup.dispatchRestoreInstanceState(PreferenceGroup.java:337)
E AndroidRuntime: at android.preference.PreferenceGroup.dispatchRestoreInstanceState(PreferenceGroup.java:337)
E AndroidRuntime: at android.preference.Preference.restoreHierarchyState(Preference.java:2048)
E AndroidRuntime: at android.preference.PreferenceFragment.onActivityCreated(PreferenceFragment.java:215)
E AndroidRuntime: at android.app.Fragment.performActivityCreated(Fragment.java:2514)
E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1323)
E AndroidRuntime: at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1581)
E AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1642)
E AndroidRuntime: at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3052)
E AndroidRuntime: at android.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3004)
E AndroidRuntime: at android.app.FragmentController.dispatchActivityCreated(FragmentController.java:184)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8045)
E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8021)
E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)

@shgrg1712
Copy link
Author

@jjoseba : Please help

@shgrg1712
Copy link
Author

@Gericop I guess you have seen similar issue earlier. Can you help me please ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant