TriangleN
TriangleN

Reputation: 337

How to wait result from OKHTTP response without freezing app

When I use CountDownLatch, the application freezes until the result is received, it is fashionable to avoid this?

Upvotes: 0

Views: 180

Answers (1)

Andrei Naumets
Andrei Naumets

Reputation: 514

You can do it in another thread. Also you can do it in coroutines

I recommend get data with

CoroutineScope(Dispatchers.IO).launch { 
   val dat = getdata()
   launch(Dispatchers.Main){ setInMyView(dat) }
}

Upvotes: 1

Related Questions