LiveData has no public available methods to update the stored data. The MutableLiveData class exposes the setValue(T) and postValue(T) methods public and you must use these if you need to edit the value stored in a LiveData object.
Which of these approaches is better/correct? To have 1 observer to such LiveData object, and have the observer to implement the update logic for all views, making the necessary checks, etc. To have multiple observers to the LiveData object (or per interested view) and each observer only deals with the logic of that particular view.
LiveData is a data holder that is lifecycle-aware, meaning it only delivers updates to observers that are in an active state. It is useful for holding data that needs to be observed and updated in the UI, such as data from a network request or a database query. State is a data holder that represents an immutable state value that can be observed.
PS The asFlow makes a flow that makes LiveData activate at starting collect. I think the solution with MediatorLiveData or Transformations and attaching a dummy observer doesn't have differences using the Flow except for emitting value from LiveData is always observed in the ViewModel instance.
ViewModel uses a MediatorLiveData to observe changes of the LiveData that comes from repository. I've added the data as a source to observe changes and remove it after it triggers to prevent firing events multiple times when I get data multiple times.
So, when I try to convert the Repository's Flow to the LiveData with the help of asLiveData method, asLiveData is underlined and studio writes that it's an unresolved reference.
I couldn't find the specific differences as there are complex examples on the internet. What are the differences in terms of performance? In which scenarios does it provide advantages? Using StateFlow with Kotlin Flow is advantageous. But what is the risk of not switching to StateFlow in a project using LiveData? Is Google deprecating LiveData? :)
I have some questions about Kotlin Flow I can observe LiveData from multiple Fragments. Can I do this with Flow? If yes then how? We can have multiple LiveData from a single LiveData using map&
4 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.