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

Spikey Sanju

09/02/2020, 11:19 AM
How to call lifecycleScope inside a composable function?
m

Manuel Vivo

09/02/2020, 11:21 AM
You might be looking for
launchInComposition
https://developer.android.com/jetpack/compose/interop#async
1
s

Spikey Sanju

09/02/2020, 11:23 AM
This is what i'm looking for thanks!
GlobalScope is working fine. But when I try to call launchInComposition it's showing this error! @Manuel Vivo
z

Zach Klippenstein (he/him) [MOD]

09/02/2020, 11:46 AM
What's the error?
s

Spikey Sanju

09/02/2020, 11:48 AM
m

Manuel Vivo

09/02/2020, 11:49 AM
That’s because
launchInComposition
should be triggered from a composable function. Here’s used in a callback which is out of the composition
t

Timo Drick

09/02/2020, 11:50 AM
You can remember:
Copy code
val scope = rememberCoroutineScope()
In the composition and than use it inside of the onClick callback
👍 4
2
m

Manuel Vivo

09/02/2020, 11:51 AM
☝️
90 Views