https://kotlinlang.org logo
#compose
Title
# compose
g

Grigorii Yurkov

10/22/2020, 3:02 PM
I have MyScreen Composable function. I want to load some data from server when this screen appears. In usual android I would use
onResume()
and what I supposed to do now.
z

Zach Klippenstein (he/him) [MOD]

10/22/2020, 3:05 PM
Probably
LaunchedTask
would be best, since it launches a coroutine that will automatically get cancelled when the function leaves the composition. If your API is callback based, you could also use
onActive
or
onCommit
with
onDispose
(soon to be renamed to
DisposableEffect
).
☝🏼 1
👍 1
a

alorma

10/26/2020, 7:01 PM
Hey. But, i cannot use composable functions inside it, isn't?
j

Jeremy

10/26/2020, 7:10 PM
z

Zach Klippenstein (he/him) [MOD]

10/26/2020, 7:20 PM
Correct, you cannot call composable functions from “effect” functions (like
onCommit
,
*Effect
)
2 Views