Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the Intent from a composable.

like image 826
S Haque Avatar asked Mar 07 '26 10:03

S Haque


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
}
like image 128
Philip Dukhov Avatar answered Mar 09 '26 00:03

Philip Dukhov