Skip to content

Conversation

@mzorz
Copy link
Contributor

@mzorz mzorz commented Oct 17, 2025

Closes #1772

Fix

What was happening
ListPreference crashes on resume because a deprecated theme value stored in SharedPreferences is an invalid index for the newly shortened resource array.

User selects 'Auto' theme (value 2) before it was deprecated.
The user's preference is stored in SharedPreferences. In an older version, the theme options included 'Auto' which corresponded to a value that is now invalid or points to a different entry.

The 'Auto' theme was removed in commit c43d0ad. The array_theme_values for API 29+ now only contains 3 items (0, 1, 2), but the user's stored value might be 3 (System) or 2 (Auto, which is now System).

0 1 2

Fix:
Added a workaround to comply with existing saved preference where the options array included more values than the new array has in newer versions, so this ListPreference extension checks for bounds to prevent IOBException and defaults to the system value

Test

  1. download the previous version of Simplenote and install it on your phone 2.34 https://github.com/Automattic/simplenote-android/releases/tag/2.34
  2. login with an account with data
  3. go to settings and select Theme "System" (fourth option)
  4. exit settings
  5. now create a release build on this branch and update the app on the same device:
    go to Build -> Generate Signed App Bundle or APK, choose APK, then populate the fields with the secret store data in gradle.properties, or ping me for to DM you a signed APK.
  6. observe you can go to settings and it doesn't crash

In the following video I show you all 3 updates:

  1. old version 2.34 working, saving to use the fourth theme option.
  2. then installing 2.36 and attempting to go to settings -> observe it crashes
  3. then installing the fix (built a signed release version locally), opening settings and it works.
Screen.Recording.2025-10-17.at.7.11.36.PM.mov

Review

Release

…ptions array included more values than the new array has in newer versions, so this ListPreference extension checks for bounds to prevent IOBException and defaults to the system value
@mzorz mzorz added this to the Future milestone Oct 17, 2025
@mzorz mzorz added [priority] high Fix/Feature needed as soon as possible. crash Bad stuff — something related to an app crash! labels Oct 17, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 17, 2025

1 Warning
⚠️ Class SafeThemeListPreference is missing tests, but unit-tests-exemption label was set to ignore this.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

📲 You can test the changes from this Pull Request in Simplenote Android by scanning the QR code below to install the corresponding build.

App NameSimplenote Android
Build TypeDebug
Commitf5b1f07
Direct Downloadsimplenote-android-prototype-build-pr1778-f5b1f07-0199f335-5204-4293-b8f1-ac52bf6d3d89.apk

Copy link

@zwarm zwarm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a single comment with regards to getValue possibly being null. Otherwise the code looks good.

) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {

override fun getSummary(): CharSequence? {
val value = getValue()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzorz - is there a change that getValueI() can return null? I'm can't tell if findIndexOfValue(value) handles that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great observation! exactly that case is handled in findIndexOfValue, so no worries 👍

@mzorz
Copy link
Contributor Author

mzorz commented Oct 17, 2025

Thank you for your review @zwarm ! 🙏

@mzorz mzorz merged commit 57de93c into trunk Oct 17, 2025
17 of 19 checks passed
@mzorz mzorz deleted the mzorz/fix-crashes-on2.36 branch October 17, 2025 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crash Bad stuff — something related to an app crash! [priority] high Fix/Feature needed as soon as possible. unit-tests-exemption

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App Crashing when accessing Settings

5 participants