0

In a googlesample I have seen that the Retrofit call object is returned as a LiveData instance.

 @GET("users/{login}")
 fun getUser(@Path("login") login: String): LiveData<ApiResponse<User>>

like so.

What benefits does this have over just waiting for the CallBack to be invoked.

Roger
  • 11
  • 1

1 Answers1

0

LiveData is one of architecture components and it's lifecycle-aware meaning that it ensures to update ui only when your lifecycle is in active state.There can be situation where you get data from network but your activity or fragment is destroyed and you update your view which may resulted in leak or crash. You can solve this problem with the help of livedata. It's worth mentioned that you can also use RxAndroid observable but you won't get lifecycle-awareness functionality.

Chan Myae Aung
  • 547
  • 3
  • 15