How to get Intent Data in a Composable

Viewed 1559

When I am starting an Activity, I am passing some data to. it via the Intent. How can I access this data from Intent inside a composable?

I am looking for a way to directly access the Intent from a composable.

1 Answers

You can get current activity from the LocalContext. And this using activity you can get intent:

val context = LocalContext.current
val activity = context.findActivity()
val intent = activity?.intent

findActivity:

fun Context.findActivity(): Activity? = when (this) {
    is Activity -> this
    is ContextWrapper -> baseContext.findActivity()
    else -> null
}
Related