Lee Delarm
10/28/2022, 6:41 PMclass MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
) {
val scope = rememberCoroutineScope()
var text by remember { mutableStateOf("Loading") }
LaunchedEffect(true) {
scope.launch {
text = try {
Greeting().greeting()
} catch (e: Exception) {
e.localizedMessage ?: "error"
}
}
}
Greeting(text)
}
}
}
}
}
zsmb
10/28/2022, 7:04 PMLaunchedEffect
already starts a coroutine for you, so you shouldn't need to create a scope and use launch
. Just make your suspending calls within the suspending function that you're passing to LaunchedEffect
.Lee Delarm
10/28/2022, 7:48 PMdelay(3000)
in its place and it WILL run then. So I'm guessing I messed up using Ktro somehow
val rockets: List<RocketLaunch> =
httpClient.get("<https://api.spacexdata.com/v4/launches>").body()
val lastSuccessLaunch = rockets.last { it.launchSuccess == true }
Lee Delarm
10/28/2022, 7:51 PMLee Delarm
10/28/2022, 7:58 PM