androidandroid-jetpack-composeonbackpressedandroid-jetpack-navigation

Jetpack Compose BackPressHandler fails to intercept back presses after onResume


In my Jetpack Compose project I'm using BackPressHandler from Android examples. Everything works as expected until I pause and resume the app. At this point BackPressHandler is not intercepting back button anymore and navigation just defaults to regular back press behaviour.

Was able to recreate the issue in a demo project, please see code example:

https://gist.github.com/vitalnik/2a444c20cb9f370c405ee1ddb86d3e66

Thanks!


Solution

  • No need to use BackPressHandler anymore, since that article was written, system BackHandler was added, so you can switch. It doesn't have such an issue.