Is there a way to call a specific composable from ...
# compose
j
Is there a way to call a specific composable from a notification? I know how the open an activity, but I'm trying to access a specific screen (the same way you would do it with a navhost)
l
Yes there's two ways. Deep links (which also discard all previous UI state), or calling the navigator, I have a draft article on that latter approach if that suits your use case better than deep links.
j
@louiscad I did find a couple or resources using deeplinks, but I'm not sure how to create them in my case, that's how my navigator looks like
Copy code
@Composable
fun Navigation(){
    
    val navController = rememberNavController()
    val uri = "excerpts"
    
    NavHost(navController = navController, startDestination = Screen.Home.route ){

        composable(route = Screen.Home.route){ HomeScreen(navController)}

        composable(route = Screen.DayCardFull.route){ DayCardFullScreen()}

        composable(route = Screen.Settings.route){ SettingsScreen() }



    }
    
}
I'm trying to open SettingsScreen from the notification.
Looking forward to read the article about the other method!
l
Creating a deep link is not relying on Compose APIs FYI
j
Yes, I think I do get that. I tried to mimic this article, but in my case there is no"id", so I don't understand how to adapt i to my case. https://proandroiddev.com/open-composables-via-notification-with-jetpack-navigation-b922384f4091
i
What makes you think any kind of ID is required? Just leave it out if you don't need it
j
@louiscad I got it to work using deeplinks. However, it seems like the uri has to be in the "https..." format, which in my case is confusing because everything is running locally (I'm using a fake url now). Please ping when you publish your article about the navigator method.
i
You can use whatever deep link you want, as long as it is a valid Uri excerpts://nav/day would be a valid deep link. Note that the intent filter part is also completely optional - your Intent can specify exactly what ComponentName you want (i.e., what activity)
🙇‍♂️ 1
👍 1