adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.6k stars 139 forks source link

BackHandler not working correctly after app is opened from recents app menu #156

Open AntsyLich opened 1 year ago

AntsyLich commented 1 year ago

If an Android app using Voyager is closed and then opened from the Recent Apps menu, pressing the back button may trigger the BackHandler of a different screen in the navigation stack instead of the current screen's BackHandler.

In the provided video testing the Tachiyomi app, the first 5 seconds demonstrate the normal behavior, where pressing the back button deselects the selected item, and further pressing the back button shows a toast message to confirm exiting the app, closing it if back button is pressed again. However, in the remaining part of the video, the broken behavior is observed. Pressing the back button confirms the exit without deselecting the item. Even after the item is selected again it still confirms the exit first without deselecting the item itself.

[VIDEO HERE]

From my understanding the BackHandler order isn't being preserved and gets shuffled? Maybe related to #10?

AntsyLich commented 1 year ago

There's this similar issue with NavHost (https://issuetracker.google.com/issues/279118447) and the solution they came up with is to integrate BackHandler into NavHost.

AntsyLich commented 1 year ago

I did a little more digging and https://issuetracker.google.com/issues/278424779 might be issue. When screens are being restored they probably aren't being restored in the right order