79079620

Date: 2024-10-11 20:21:29
Score: 1
Natty:
Report link

When you want to change the UI, you have to do it on the main thread. So, you get data in the IO thread and then update the UI on the main thread

Here is the code:

button.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
    val url = mainApi.loadMyImage()
    withContext(Dispatchers.Main){              
        Picasso.with(requireContext()).load(url)
            .into(imgView)
        }
    }
}
Reasons:
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (1):
Posted by: Yakup Kavak