@Test public void testWeak() throws InterruptedException { final AtomicInteger data = new AtomicInteger(0); InvalidationTracker.Observer observer = new InvalidationTracker.Observer("a") { @Override public void onInvalidated(@NonNull Set<String> tables) { data.incrementAndGet(); } }; mTracker.addWeakObserver(observer); setVersions(1, 0); refreshSync(); assertThat(data.get(), is(1)); observer = null; forceGc(); setVersions(2, 0); refreshSync(); assertThat(data.get(), is(1)); }
@SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); }
InvalidationTracker { @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); } }
InvalidationTracker { @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); } @SuppressWarnings("WeakerAccess") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  InvalidationTracker(RoomDatabase database, String... tableNames); }
InvalidationTracker { @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); } @SuppressWarnings("WeakerAccess") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  InvalidationTracker(RoomDatabase database, String... tableNames); @WorkerThread void addObserver(@NonNull Observer observer); @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addWeakObserver(Observer observer); @SuppressWarnings("WeakerAccess") @WorkerThread void removeObserver(@NonNull final Observer observer); @SuppressWarnings("WeakerAccess") void refreshVersionsAsync(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread void refreshVersionsSync(); }
InvalidationTracker { @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public void addWeakObserver(Observer observer) { addObserver(new WeakObserver(this, observer)); } @SuppressWarnings("WeakerAccess") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  InvalidationTracker(RoomDatabase database, String... tableNames); @WorkerThread void addObserver(@NonNull Observer observer); @SuppressWarnings("unused") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void addWeakObserver(Observer observer); @SuppressWarnings("WeakerAccess") @WorkerThread void removeObserver(@NonNull final Observer observer); @SuppressWarnings("WeakerAccess") void refreshVersionsAsync(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread void refreshVersionsSync();  }