Returning a value after callback in Kotlin

前端 未结 2 1470
借酒劲吻你
借酒劲吻你 2021-01-29 05:40

How can I return a value after a callback in kotlin, I tried using Thread.sleep but it doesn\'t work

   fun searchColorFromAPI(): Colors {
    val service: Retro         


        
2条回答
  •  梦毁少年i
    2021-01-29 06:02

    1. You can use live data ,that gets updated once the callback receives ,the same live data is observed by the caller fragment/activity

    2. You can use coroutines to return a value from function which has asyn calls in it.

    3. You can use interface callbacks to activity/ fragment to trigger the updates received from retrofit calls.

提交回复
热议问题