Michael
Michael

Reputation: 790

Navigate to another app with navigation component and composable

I'm creating an app with navigation component and composable. Imagine that I have an Android app with navHost like this:

NavHost(
    navController = navController,
    startDestination = RallyScreen.Overview.name,
    modifier = Modifier.padding(innerPadding)
) {
    composable(RallyScreen.Overview.name) { 
      Text(RallyScreen.Overview.name)
    }
    composable(RallyScreen.Accounts.name) {
        Text(RallyScreen.Accounts.name) 
    }
    composable(RallyScreen.Bills.name) { 
        Text(RallyScreen.Bills.name) 
    }
}

I wonder how can I define navigation to another app like Gmail, or any other apps.

Upvotes: 0

Views: 215

Answers (1)

Stefano Sansone
Stefano Sansone

Reputation: 2709

Maybe someone more experienced will correct me, but I think this is not the correct way to approach the problem.
In a nutshell, the NavHost is used to link routes to composables functions of your app, and handle the in-app navigation. Why you want to create a link to another app here? What are you trying to do ?

Rather, in one of your composables functions, you will have for example a button, which starts an activity with an intent.

Button(
    onClick = { startActivity(intent) }
) {
    Text(text = "Button")
}

You can also do this with the BottomNavigation by using the onClick property of the BottomNavigationItem.

Upvotes: 1

Related Questions