Skip to content Skip to sidebar Skip to footer

How To Get Intent Data In A Composable

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

Solution 1:

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 -> thisis ContextWrapper -> baseContext.findActivity()
    else -> null
}

Post a Comment for "How To Get Intent Data In A Composable"