How to get Context in Jetpack Compose
Update March 2021: The previous answer has been deprecated. You should now use:
val context = LocalContext.current
Previous answer for reference:
You can access to context with define ambientContext
.
Example:
val context = ContextAmbient.current
ContextAmbient
and AmbientContext
has been deprecated.
You can replace them with LocalContext
Example:
val context = LocalContext.current
is deprecated as of ContextAmbient.current
alpha-09
.
is deprecated. I think as of AmbientContext.current
alpha-11
.
LocalContext.current
is how you get the context in a composable now.