Skip to content

Fix crash after rotating the screen with automatic location recording on in geoshape and geotrace#7019

Closed
grzesiek2010 wants to merge 2 commits intogetodk:masterfrom
grzesiek2010:COLLECT-6999
Closed

Fix crash after rotating the screen with automatic location recording on in geoshape and geotrace#7019
grzesiek2010 wants to merge 2 commits intogetodk:masterfrom
grzesiek2010:COLLECT-6999

Conversation

@grzesiek2010
Copy link
Member

@grzesiek2010 grzesiek2010 commented Jan 13, 2026

Closes #6999

Why is this the best possible solution? Were any other approaches considered?

Replaced ScheduledExecutorService with a lifecycle-aware coroutine in GeoPolyFragment to handle automatic GPS recording. This ensures recording stops safely when the view is destroyed, preventing crashes on rotation or backgrounding. Using ScheduledExecutorService / ScheduledFuture is discouraged because it’s less lifecycle-aware and can easily lead to memory leaks or background work running after the view is destroyed.

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?

I’ve reworked the automatic recording functionality for geotrace and geoshape questions, so please not only verify that the crash no longer occurs, but also test the feature for any regressions.

Do we need any specific form for testing your changes? If so, please attach one.

The form is attached to the issue

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • added or modified tests for any new or changed behavior
  • run ./gradlew connectedAndroidTest (or ./gradlew testLab) and confirmed all checks still pass
  • added a comment above any new strings describing it for translators
  • added any new strings with date formatting to DateFormatsTest
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@grzesiek2010 grzesiek2010 marked this pull request as ready for review January 13, 2026 11:21
@grzesiek2010 grzesiek2010 requested a review from seadowg January 13, 2026 11:21
Copy link
Member

@seadowg seadowg left a comment

Choose a reason for hiding this comment

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

I'm a little worried that there could be regression in the stability of recording traces/shapes in the background with this change. The old solution was definitely not right, but it did appear to work for people pocketing their phone.

I think this should potentially use the Fragment's lifecycle rather than the Fragment's view lifecycle for simplicity, but as far as I can tell, this should work with the app in the background - the only scenario that the Fragment should be destroyed in is if the host Activity is killed as part of a full process kill and that isn't something we can prevent/work around.

That said, this kind of work should usually be handled by a foreground service and I think we can piggyback on the LocationTracker which is already being used here by exposing the current location as a StateFlow that gets updated on each location update (and then observing that as LiveData). I've actually just hit a point in #7017 where it would be useful to have the trace/shape state stored for GeoPolyFragment in a ViewModel rather than in the MapFragment so that I don't have to update every single MapFragment#getPolylinePoints implementation. Given that, I could take on that LocationTracker version as part of that, and we park this? What do you think? Alternatively, you could do the LocationTracker version here and I can just integrate that in.

@grzesiek2010
Copy link
Member Author

I'm a little worried that there could be regression in the stability of recording traces/shapes in the background with this change. The old solution was definitely not right, but it did appear to work for people pocketing their phone.

Ahh right I thought that would be stooped but you are right.

ok let's wait for #7017

@seadowg seadowg marked this pull request as draft January 13, 2026 12:56
@seadowg seadowg mentioned this pull request Jan 15, 2026
6 tasks
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

Successfully merging this pull request may close these issues.

Crash after rotating the screen with automatic location recording on in geoshape and geotrace

2 participants