Skip to content
Back to skills

Android Navigation 3

ASecurity

Give each bottom-navigation tab its own `mutableStateListOf<Any>`. Switching tabs changes which list is supplied to `NavDisplay`, so each tab retains its independent navigation history. ```kotlin enum class Tab(val label: String, val startRoute: Any) { Home("Home", RouteHome), Search("Search", RouteSearch), Profile("Profile", RouteProfile) } data object RouteHome data object RouteSearch data object RouteProfile data class RouteDetail(val id: String) @Composable fun MainScreen() { val tabs = r...

  • 584 stars
  • 0 votes
  • 0 copies
  • 9 views
  • Added September 5, 2026
developmentkotlin

Works with

  • cli

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-navigation-3 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Android Navigation 3?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Android Navigation 3
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-android-navigation-3-63e0bc09/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-navigation-3-63e0bc09)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# Bottom navigation with multiple back stacks

Give each bottom-navigation tab its own `mutableStateListOf<Any>`. Switching tabs changes which list is supplied to `NavDisplay`, so each tab retains its independent navigation history.

```kotlin
enum class Tab(val label: String, val startRoute: Any) {
    Home("Home", RouteHome),
    Search("Search", RouteSearch),
    Profile("Profile", RouteProfile)
}

data object RouteHome
data object RouteSearch
data object RouteProfile
data class RouteDetail(val id: String)

@Composable
fun MainScreen() {
    val tabs = remember { Tab.entries.toList() }
    var selectedTab by remember { mutableStateOf(Tab.Home) }

    val backStacks = remember {
        tabs.associateWith { tab ->
            mutableStateListOf<Any>(tab.startRoute)
        }
    }

    val currentBackStack = backStacks.getValue(selectedTab)

    Scaffold(
        bottomBar = {
            NavigationBar {
                tabs.forEach { tab ->
                    NavigationBarItem(
                        selected = selectedTab == tab,
                        onClick = { selectedTab = tab },
                        icon = { /* tab icon */ },
                        label = { Text(tab.label) }
                    )
                }
            }
        }
    ) { innerPadding ->
        NavDisplay(
            backStack = currentBackStack,
            onBack = { currentBackStack.removeLastOrNull() },
            modifier = Modifier.padding(innerPadding),
            entryProvider = { key ->
                when (key) {
                    is RouteHome -> NavEntry(key) {
                        HomeScreen(
                            onOpenDetail = { id ->
                                currentBackStack.add(RouteDetail(id))
                            }
                        )
                    }

                    is RouteSearch -> NavEntry(key) {
                        SearchScreen(
                            onOpenDetail = { id ->
                                currentBackStack.add(RouteDetail(id))
                            }
                        )
                    }

                    is RouteProfile -> NavEntry(key) {
                        ProfileScreen()
                    }

                    is RouteDetail -> NavEntry(key) {
                        DetailScreen(id = key.id)
                    }

                    else -> error("Unknown route: $key")
                }
            }
        )
    }
}
```

The important part is that `backStacks` is created once with `remember`; recreating the map on every recomposition would discard the tab histories. For example:

1. Home starts as `[RouteHome]` and opens `RouteDetail("a")`.
2. Switching to Search renders `[RouteSearch]` without changing Home's list.
3. Search can build its own stack, such as `[RouteSearch, RouteDetail("b")]`.
4. Returning to Home renders `[RouteHome, RouteDetail("a")]` again.

Back presses operate on the currently selected tab's list. The root entry can be protected if the app should not allow an empty stack:

```kotlin
onBack = {
    if (currentBackStack.size > 1) {
        currentBackStack.removeLast()
    }
}
```

This is state-driven Navigation 3: there is no `NavController`, no string route matching, and no shared global back stack. If the product wants a reselected tab to return to its root, explicitly clear that tab's list and add its `startRoute`; otherwise leave it untouched to preserve the current tab history.

Files in this skill

  • eval-1.baseline.md2.4 KB
  • eval-1.with-skill.md2.4 KB
  • eval-2.baseline.md2.9 KB
  • eval-2.with-skill.md2.9 KB
  • eval-3.baseline.md4.7 KB
  • eval-3.with-skill.md3.4 KB
  • trigger-1.md147 B
  • trigger-2.md141 B
  • trigger-3.md121 B
  • trigger-4.md121 B
  • trigger-5.md107 B
  • trigger-6.md115 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.