InvalidationTracker

public class InvalidationTracker


InvalidationTracker keeps a list of tables modified by queries and notifies its callbacks about these tables.

Summary

Nested types

public abstract class InvalidationTracker.Observer

An observer that can listen for changes in the database.

Public methods

void

Adds the given observer to the observers list and it will be notified if any table it observes changes.

void

Enqueues a task to refresh the list of updated tables.

void

Removes the observer from the observers list.

Public methods

addObserver

Added in 2.0.0
@WorkerThread
public void addObserver(@NonNull InvalidationTracker.Observer observer)

Adds the given observer to the observers list and it will be notified if any table it observes changes.

Database changes are pulled on another thread so in some race conditions, the observer might be invoked for changes that were done before it is added.

If the observer already exists, this is a no-op call.

If one of the tables in the Observer does not exist in the database, this method throws an IllegalArgumentException.

This method should be called on a background/worker thread as it performs database operations.

Parameters
@NonNull InvalidationTracker.Observer observer

The observer which listens the database for changes.

refreshVersionsAsync

Added in 2.0.0
public void refreshVersionsAsync()

Enqueues a task to refresh the list of updated tables.

This method is automatically called when RoomDatabase.endTransaction is called but if you have another connection to the database or directly use [ ], you may need to call this manually.

removeObserver

Added in 2.0.0
@WorkerThread
public void removeObserver(@NonNull InvalidationTracker.Observer observer)

Removes the observer from the observers list.

This method should be called on a background/worker thread as it performs database operations.

Parameters
@NonNull InvalidationTracker.Observer observer

The observer to remove.