Skip to content

Commit

Permalink
Update LiveData value when becoming active
Browse files Browse the repository at this point in the history
Allow LiveData to stay up to date, especially when resuming an activity
  • Loading branch information
RemiLatapy committed Nov 15, 2018
1 parent 314d9af commit 6a85b71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected void onActive() {
super.onActive();
T object = getValue();
if (object != null && RealmObject.isValid(object)) {
setValue(object);
RealmObject.addChangeListener(object, listener);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public LiveRealmResults(@NonNull RealmResults<T> results) {
protected void onActive() {
super.onActive();
if (results.isValid()) { // invalidated results can no longer be observed.
LiveRealmResults.this.setValue(results);
results.addChangeListener(listener);
}
}
Expand Down

0 comments on commit 6a85b71

Please sign in to comment.