Skip to content

Fix crash when Snackbar callback triggered after fragment detach#6911

Merged
seadowg merged 1 commit intogetodk:v2025.3.xfrom
grzesiek2010:barcode-dismiss2
Oct 1, 2025
Merged

Fix crash when Snackbar callback triggered after fragment detach#6911
seadowg merged 1 commit intogetodk:v2025.3.xfrom
grzesiek2010:barcode-dismiss2

Conversation

@grzesiek2010
Copy link
Member

@grzesiek2010 grzesiek2010 commented Sep 30, 2025

This should prevent a crash we've seen on Crashlytics.

Steps to reproduce the issue:

  1. Open the barcode widget
  2. Scan any code
  3. Press the device back button immediately after the code is scanned

The crash occurs because the fragment gets detached, and then the Snackbar callback still tries to handle the scanned code.

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

This is the easiest solution. One alternative approach could be to dismiss the Snackbar when the fragment is detached to avoid handling the callback, but that would likely be more complex.

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?

It should just fix the issue. I can't think of any risk here that we should take into account.

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

No.

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 changed the base branch from master to v2025.3.x September 30, 2025 12:13
@grzesiek2010 grzesiek2010 marked this pull request as ready for review September 30, 2025 12:31
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.

Good catch!

@alyblenkin I think it'd be worth having a think about this flow: scanning a barcode and then hitting back while the snackbar is showing. Currently, that's going to return the user to the form, but not save the value.

@seadowg seadowg merged commit f0c39bf into getodk:v2025.3.x Oct 1, 2025
6 checks passed
@alyblenkin
Copy link
Collaborator

Interesting! If they scanned the barcode successfully and they hit back I would assume the value should be saved. If you hit back before it saved, I would expect to go back to get barcode button / page.

When we remove this interstitial state (green state and snackbar) as part of #6914 you won't be able to get into this scenario.

grzesiek2010 pushed a commit to grzesiek2010/collect that referenced this pull request Oct 13, 2025
Fix crash when Snackbar callback triggered after fragment detach
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.

3 participants