When I use
LaunchedEffect(Dispatchers.IO)
I get,
NetworkOnMainThreadException
How should I use this function to run on background thread?
this is my code:
LaunchedEffect(Dispatchers.IO) {
val input = URL("https://rezaapp.downloadseriesmovie.ir/maintxt.php").readText()
println(input)
}
I'm using it inside my jetpack compose project
You should take a look at what LaunchedEffect does first. In your code, you placed Dispatchers.IO as the key and not as the Dispatcher to use.
Since LaunchedEffect will have a block of CoroutineScope.() -> Unit, you can switch thread within this block like the following :
LaunchedEffect {
launch(Dispatchers.IO) {
val input = URL("https://rezaapp.downloadseriesmovie.ir/maintxt.php").readText()
println(input)
}
}
Hopefully this is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With