-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Extract Main Menu to Fragment to prevent lifecycle crashes #5829
Conversation
collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuFragment.kt
Show resolved
Hide resolved
collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuActivity.kt
Outdated
Show resolved
Hide resolved
In the CircleCI apk if Google maps aren't available should they by default switch to OSM - is the PR introducing it in the apk? |
This branch has been started from v2023.3.x because it will be a point release for that version but Fallback to OSM if other engines aren't available has been merged into master and not to v2023.3.x |
Tested with Success! Verified cases:
|
Tested with Success! Verified on device with Android 10 |
Extract Main Menu to Fragment to prevent lifecycle crashes
Extract Main Menu to Fragment to prevent lifecycle crashes
A few crashes we're seeing seem to be due to
MainMenuActivity#onResume
being called after we've returned fromonCreate
early (like in the case of there being no project or if there was a crash previously) even though we don't think that should be possible. Example reports can be found here and here.I wanted to have a quick go at moving the Main Menu view and logic into a Fragment as this would allow us to only load the Fragment when we want to actually display it which prevents problems with lifecycle being called that we want to skip.
Why is this the best possible solution? Were any other approaches considered?
The original solution to this was to have a "launch" Activity with
noHistory=true
(or that finishes itself) that handles the initial navigation. However, this causes problems for application restarts as that Activity would not be part of the back stack so the logic would be skipped.Like we've experimented with in
EntityBrowserActivity
, I think we most likely want the "form management" portion of the app to be hosted in a single Activity and multiple Fragments using the new(ish) Jetpack Navigation component, and this is a good first step towards that. I should also note that I've not made the switch to things like Fragment results or MenuProvider inMainMenuFragment
to keep this a short piece of work. That's definitely something we can add on later.How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Only the main menu has changed, but it's obviously an important part of the app so playing with it as much as possible would be good.
Before submitting this PR, please make sure you have:
./gradlew checkAll
and confirmed all checks still pass OR confirm CircleCI build passes and run./gradlew connectedDebugAndroidTest
locally.