I've been building an app entirely with Jetpack Compose and I have noticed that in the last 3 o 4 canary versions of the Android Studio, the tools are getting worse and worse (at least for me) because I can see now CPU at 200% and especially, missing references.
So I have a Toolbar component and I have an action to share a certain screen with other uses by using Intent.createChooser. This is already working, because I created it with previous
versions of the AS Canary but now, always get the following error:
Unresolved reference: Intent
Unresolved reference: action
Unresolved reference: putExtra
Unresolved reference: type
This is the code I'm using inside my TopAppBar:
actions = {
if (addShareButton) {
val context = AmbientContext.current
IconButton(
onClick = {
viewState.job?.let {
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "I have found a remote job! ${it.url}")
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
context.startActivity(shareIntent)
}
},
modifier = Modifier.align(Alignment.CenterVertically)
) {
Icon(imageVector = Icons.Default.Share)
}
}
Also, AS gives a warning saying that the the variable context defined in the line val context = AmbientContext.current is never used, but it is in the line context.startActivity(shareIntent).
Am I doing something wrong? It is now impossible to code anything because of this and other errors.
Thanks in advance!