Daniele B
05/04/2021, 10:21 AMpawegio
05/04/2021, 10:35 AMDaniele B
05/04/2021, 10:57 AMDaniele B
05/04/2021, 11:19 AMpawegio
05/04/2021, 11:22 AMBackHandler
. Few weeks ago I wrote a blog post about how it works: https://dev.to/pawegio/handling-back-presses-in-jetpack-compose-50d5Daniele B
05/04/2021, 11:23 AMIan Lake
05/04/2021, 1:24 PMBackHandler
to forward events to NavController - that code, for instance, doesn't handle the cases where there is no back stack correctlyIan Lake
05/04/2021, 1:24 PMIan Lake
05/04/2021, 1:26 PMBackHandler
is to be the right dispatch ordering: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1619810151234400?thread_ts=1619801021.217600&cid=CJLTWPH7SIan Lake
05/04/2021, 1:27 PMIan Lake
05/04/2021, 1:29 PMcurrentBackStackEntryAsState()
, which will update whenever the destination changesIan Lake
05/04/2021, 1:30 PMIan Lake
05/04/2021, 1:31 PMpawegio
05/04/2021, 3:53 PMBackHandler
just intercepts system back presses, but there are also different actions that pop the back stack.
However, regarding this:
Generally, you shouldn’t be using aFor the sake of code snippet simplicity, I skipped passing it to the view model and handling it in the business logic layer. Is your recommendation to explicitly not pop the back stack this way, because it’s more complicated internally?to forward events to NavController - that code, for instance, doesn’t handle the cases where there is no back stack correctlyBackHandler
Ian Lake
05/04/2021, 3:56 PMBackHandler