Skip to content

Fix data collection crash when UI state isn't Ready#3783

Open
andreia-ferreira wants to merge 3 commits into
masterfrom
andreia/3432/fix-ui-state-not-ready
Open

Fix data collection crash when UI state isn't Ready#3783
andreia-ferreira wants to merge 3 commits into
masterfrom
andreia/3432/fix-ui-state-not-ready

Conversation

@andreia-ferreira

@andreia-ferreira andreia-ferreira commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes #3450
Fixes #3432

There were crashes on the data collection screen, where the VM expected the UI state to be Ready when it wasn't. One way to reproduce it is:
1- Set 'No background processes' in Developer options->Background process limit
2 - Initiate data collection and send the app to the background midway through the survey
3 - Open other apps to be sure that the app process is killed
4 - Return to the app and press the back button and see that it crashes

This happens after the OS kills the app process (usually because of low memory), the back stack and saved state are restored while everything else has to be recreated from scratch, so the app reopens directly on data collection while MainViewModel is still running reactivateLastSurvey which populates the activeSurvey flow. The screen sits in Loading awaiting the active survey to finish loading (or Error, if it fails) , and a back press in that moment crashes the app.

This PR updates this logic, moving most of onBack to a dedicated method in the VM, which will handle the different uiStates accordingly and showing the exit warning if a user exits in the middle of a loading. This was also covered with unit tests.

Before

Screen_recording_20260612_164333.webm

After

Screen_recording_20260612_163811.webm

@shobhitagarwal1612 PTAL?

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.66%. Comparing base (c167392) to head (80334a4).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3783      +/-   ##
============================================
+ Coverage     66.60%   66.66%   +0.06%     
- Complexity     1684     1689       +5     
============================================
  Files           392      392              
  Lines         10145    10147       +2     
  Branches       1295     1298       +3     
============================================
+ Hits           6757     6765       +8     
+ Misses         2711     2708       -3     
+ Partials        677      674       -3     
Files with missing lines Coverage Δ
...ndroid/ui/datacollection/DataCollectionFragment.kt 90.90% <100.00%> (-1.69%) ⬇️
...droid/ui/datacollection/DataCollectionViewModel.kt 80.32% <100.00%> (+3.53%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

org.groundplatform.android.ui.datacollection.DataCollectionViewModel.isAtFirstTask [Trending] IllegalStateException: UI state not Ready, was: Loading

1 participant