How to update LiveData of a ViewModel from background service and Update UI

前端 未结 5 1330
梦毁少年i
梦毁少年i 2020-12-07 12:56

Recently I am exploring Android Architecture, that has been introduced recently by google. From the Documentation I have found this:

public class MyViewModel         


        
5条回答
  •  温柔的废话
    2020-12-07 13:42

    Take a look at the Android architecture guide that accompanies the new architecture modules like LiveData and ViewModel. They discuss this exact issue in depth.

    In their examples they don't put it in a service. Take a look at how they solve it using a "repository" module and Retrofit. The addendums at the bottom include more complete examples including communicating network state, reporting errors, etc.

提交回复
热议问题