Yusuf Ibragimov
11/07/2024, 4:06 AMIan Lake
11/07/2024, 4:59 AMnavigate(Destination.SpecificScreen(id = 12))
then popBackStack(Destination.SpecificScreen(id = 12))
will work. Otherwise, you would not expect it to work. Is that how you navigated to that screen?Yusuf Ibragimov
11/07/2024, 5:24 AMIan Lake
11/07/2024, 5:26 AMYusuf Ibragimov
11/07/2024, 5:27 AMIan Lake
11/07/2024, 5:27 AMpopBackStack<Destination.SecondScreen>()
Yusuf Ibragimov
11/07/2024, 5:32 AMIan Lake
11/07/2024, 5:34 AMIan Lake
11/07/2024, 5:35 AMYusuf Ibragimov
11/07/2024, 5:43 AM{
val activity = (LocalContext.current as? Activity)
LaunchedEffect(activity, navHostController, navigationChannel) {
navigationChannel.receiveAsFlow().collect { intent ->
if (activity?.isFinishing == true) return@collect
when (intent) {
is NavigationIntent.NavigateTo -> {
val curDestination = navHostController.currentDestination
Timber.i("WWW SS ${intent.route is Destination.Passcode}")
if (curDestination?.route?.contains("Passcode") == true) {
if (intent.route is Destination.Passcode) {
return@collect
}
}
navHostController.navigate(intent.route) {
launchSingleTop = intent.isSingleTop
//restoreState = true
intent.popUpToRoute?.let { popUpToRoute ->
popUpTo(popUpToRoute) { inclusive = intent.inclusive }
}
}
}
is NavigationIntent.NavigateBack -> {
Timber.i("www state=${navHostController.currentBackStackEntry?.lifecycle?.currentState}")
if (navHostController.currentBackStackEntry?.lifecycle?.currentState == Lifecycle.State.RESUMED) {
val route = intent.route
Timber.i("Lifecycle.State.RESUMED route=${route}")
if (route == null) {
navHostController.popBackStack()
} else {
navHostController.popBackStack(route)
}
}
}
is NavigationIntent.ClearBackStack -> {
navHostController.navigate(Destination.Auth) {
this.popUpTo(0)
}
}
}
}
}
}
Yusuf Ibragimov
11/07/2024, 5:58 AM@Serializable
data class AddMerchantToHomeScreen(val id: Long = -1, val homeId: Long) : Destination
But it ends with an error. Can you give me links to any example or instructions? @Ian LakeIan Lake
11/07/2024, 6:06 AMif (route == null) {
navHostController.popBackStack()
} else {
// Pop until we get to the destination you want, comparing only the class
while (navHostController.currentBackStackEntry?.destination?.hasRoute(route::class) == false)
navHostController.popBackStack()
}
// Then if inclusive, pop one more time
if (intent.inclusive) {
navHostController.popBackStack()
}
}
Ian Lake
11/07/2024, 6:06 AMYusuf Ibragimov
11/07/2024, 6:29 AMYusuf Ibragimov
11/07/2024, 12:16 PMYusuf Ibragimov
11/08/2024, 4:59 AMIan Lake
11/08/2024, 5:04 AMYusuf Ibragimov
11/08/2024, 5:23 AMIan Lake
11/08/2024, 5:24 AMYusuf Ibragimov
11/08/2024, 5:25 AMIan Lake
11/08/2024, 5:25 AMIan Lake
11/08/2024, 5:26 AMYusuf Ibragimov
11/08/2024, 5:27 AMYusuf Ibragimov
11/13/2024, 5:31 AMjava.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 1
at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
at java.util.Objects.checkIndex(Objects.java:359)
at java.util.ArrayList.get(ArrayList.java:434)
at V2.m$j.invokeSuspend(SourceFile:43)
at Y4.a.resumeWith(SourceFile:12)
at t5.b0.run(SourceFile:99)
at m1.B.performTrampolineDispatch(SourceFile:7)
at m1.B.access$performTrampolineDispatch(SourceFile:1)
at m1.B$d.run(SourceFile:3)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:9063)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Suppressed: y5.j: [m1.m0@903840f, A0.h@b55fc9c, W0{Cancelling}@33c46a5, B@6ce8a7a]
2024-11-13 10:25:04.793 19455-19481 ShellBackPreview com.android.systemui E Received BackNavigationInfo is null.
Yusuf Ibragimov
11/13/2024, 5:33 AMis NavigationIntent.NavigateBack -> {
val backStackEntry = navHostController.currentBackStackEntry
if (backStackEntry?.lifecycle?.currentState == Lifecycle.State.RESUMED) {
val route = intent.route
if (route == null) {
popBackStack(navHostController, activity)
} else {
Timber.d("TTT popBackStacked with while")
// Pop until we get to the destination you want, comparing only the class
while (navHostController.currentBackStackEntry?.destination?.hasRoute(route::class) == false)
popBackStack(navHostController, activity)
// Then if inclusive, pop one more time
if (intent.inclusive) {
popBackStack(navHostController, activity)
}
}
}
}