I've got two Objects (Object1 and Object2) saved via Android Room, which I want to access using LiveData. Object1
contains a reference to Object2
.
public class Object1 {
...
private Object2 object2;
...
}
I want to pass a LivaData<List<Object1>>
containing all my Objects from the ViewModel to the Activities, each Object1
already heaving stored the reference to the matching Object2
(Object1 stores the Id of Object2 in the Database).
What is the best way to combine the objects? I found MediatorLiveData and MutableLiveData but couldn't find an example that seemed useful for my case.
Edits:
About the whole situation: Object1
is some data I'm loading from the web and caching via Android Room. Object2
is some additional data which users can save locally, always concerning the data from one specific Object1
. So every Object2
is related to an Object1
but not every Object1
has an Object2
. Finally I want to pass an Object to the UI, containing all the data from the web and (if there is any) all additional data, users added to it.
The problem: I don't know what's the most efficient way to match the data from two different data sources in a way that the LiveData always updates when one of them is changed.
Thanks for helping me out whilst learning Android