Automattic / Automattic/simplenote-android
Incorrect behavior of app background state
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 318
- Avg merge
- 15h 23m
- Merged PRs (30d)
- 5
Description
Not something I experienced while using the app, but something I noticed while having a look at the source code.
The `mIsInBackground` state in `Simplenote.java` is set to false when an `onTrimMemory()` event other than `TRIM_MEMORY_UI_HIDDEN` happens. See: https://github.com/Automattic/simplenote-android/blob/develop/Simplenote/src/main/java/com/automattic/simplenote/Simplenote.java#L338
I believe this is incorrect. `onTrimMemory()` can be called with other values for `level` while the app is in the background, so then `mIsInBackground` will be incorrectly set to false. See: https://developer.android.com/reference/android/content/ComponentCallbacks2
A quick fix could be to remove the `else` of that `if` statement. But maybe using ProcessLifecycleOwner instead of ComponentCallbacks2 would be a more suited solution: https://developer.android.com/reference/androidx/lifecycle/ProcessLifecycleOwner
Contributor guide
Research direction
Start in Simplenote/src/main/java/com/automattic/simplenote/Simplenote.java around the onTrimMemory() handler at line 338, and compare its state transitions with the ComponentCallbacks2 documentation. Determine how background state should behave for memory levels other than TRIM_MEMORY_UI_HIDDEN, then verify that mIsInBackground remains accurate while the app is backgrounded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100