If I understand it correctly when there is no active observer for a LiveData object, it doesn’t get changes of the source anymore, for example, it doesn’t require to get changes from SQLite (LiveData in Dao). If again one of its observers becomes active, does it get the data from the source first or it waits for next changes on the source to become updated?
Edit: Considering the comments, I think I should explain my question more precisely. Indeed, my question is about when LiveData itself becomes active. For example, I have following Dao:
@Dao
public interface SampleDao {
…
@Query("SELECT * FROM sampleTable where createdAt > :ceatedAt")
LiveData<List<sampleEntity>> newSampleEntities(Date ceatedAt);
…
}
And its returned LiveData from newSampleEntities has just one observer, namely activity1. Suppose that sampleEntity1 is inserted in sampleTable. Consequently, Livedata gets it through a query and informs activity1 about it. If activity1 becomes paused (onPause() is called), the Livedata doesn’t have any active observer anymore. So It becomes inactive and doesn’t requery sampleTable anymore. Suppose that sampleEntity1 is deleted from sampleTable and sampleEntity2 is inserted in it. Since the LiveData doesn’t get changes, it has sampleEntity1 yet. Now, suppose that activity1 becomes resumed and consequently the Livedata becomes active again. I want to know when the LiveData gets updated about changes in sampleTable. Does it requery sampleTable before becoming active?