-
public final class NavBackHandlerKt
-
-
Method Summary
Modifier and Type Method Description final static <T extends Any> <ERROR CLASS>NavBackHandler(NavController<T> controller, Boolean enabled, Boolean allowEmptyBackstack)Convenient BackHandler implementation that supports the most basic logic of back navigation. -
-
Method Detail
-
NavBackHandler
@Composable() final static <T extends Any> <ERROR CLASS> NavBackHandler(NavController<T> controller, Boolean enabled, Boolean allowEmptyBackstack)
Convenient BackHandler implementation that supports the most basic logic of back navigation.
The underlying BackHandler will be kept enabled while the controller contains more than one entry in its backstack. The back button press will cause a single NavController.pop. This way the back handling may be delegated to upper
BackHandlerswhen there are no more items to pop off without leaving the backstack completely empty.If you want to allow NavBackHandler to remove the last entry as well, you may set allowEmptyBackstack to
true. For example,allowEmptyBackstack = trueshould be used in pair withBottomSheetNavHost.For any more specific use-cases feel free to use BackHandler directly and define your own behaviour.
IMPORTANT NOTICE: place your NavBackHandler or BackHandler in a composable before a corresponding NavHost. As both BackHandler and NavHost use Lifecycle under the hood, there is a case when the order of back handling may be restored incorrectly after a process/activity recreation. This is how the framework works and there is nothing to do about it. Simple placement of BackHandler before NavHost guarantees no issues in this part.
- Parameters:
enabled- if this NavBackHandler should be enabled.
-
-
-
-