Skip to content

Fix crash on rapid back press by checking back stack state before removal#13

Closed
easternkite wants to merge 1 commit into
android:mainfrom
easternkite:main
Closed

Fix crash on rapid back press by checking back stack state before removal#13
easternkite wants to merge 1 commit into
android:mainfrom
easternkite:main

Conversation

@easternkite

Copy link
Copy Markdown

Summary

This PR fixes a crash that occurs when the back button is pressed rapidly while on certain screens (e.g. Create, About).

The issue was caused by backStack.removeLastOrNull() being called without validating the current top of the back stack, leading to IllegalArgumentException: NavDisplay backstack cannot be empty.

Changes

  • Added type-checks before removing the top of the back stack to ensure the app is in a valid navigation state.
  • Specifically checks if backStack.last() is of type Create or About before removing it.

@riggaroo

riggaroo commented Jun 9, 2025

Copy link
Copy Markdown
Collaborator

thanks - this will be fixed in the next version of nav3 - so we wont need to implement this fix: https://issuetracker.google.com/419017866

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.

2 participants