https://kotlinlang.org logo
#compose
Title
# compose
c

Chris Fillmore

05/10/2022, 5:37 PM
I have a composable which triggers a notification. Is there a best practice in Compose for how to obtain the
Intent
for the notification’s
setContentIntent()
? I’m trying to avoid having the composable know about its host Activity. Clicking the notification will launch that Activity. I can think of a few things I could do: • Pass in a lambda like
intent: () -> Intent
to invoke anytime I need an intent • Pass in the Activity
Class<?>
• CompositionLocal? (bad idea?)
i

Ian Lake

05/10/2022, 5:58 PM
Are you using Navigation Compose and its support for deep linking into the correct screen based on your Intent? Besides automatically parsing arguments out of the Intent's data string for you, it also gives you the raw Intent itself as an argument: https://developer.android.com/reference/androidx/navigation/NavController.Companion#KEY_DEEP_LINK_INTENT()
c

Chris Fillmore

05/10/2022, 6:00 PM
Indeed I am. Thanks for the tip!
7 Views