Search in sources :

Example 1 with ListenerRegistration

use of com.google.cloud.firestore.ListenerRegistration in project java-docs-samples by GoogleCloudPlatform.

the class ListenDataSnippets method detachListener.

/**
 * Demonstrate how to detach an event listener.
 */
void detachListener() {
    // [START detach_errors]
    Query query = db.collection("cities");
    ListenerRegistration registration = query.addSnapshotListener(new EventListener<QuerySnapshot>() {

        // [START_EXCLUDE]
        @Override
        public void onEvent(@Nullable QuerySnapshot snapshots, @Nullable FirestoreException e) {
        }
    });
    // ...
    // Stop listening to changes
    registration.remove();
// [END detach_errors]
}
Also used : Query(com.google.cloud.firestore.Query) FirestoreException(com.google.cloud.firestore.FirestoreException) ListenerRegistration(com.google.cloud.firestore.ListenerRegistration) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot)

Aggregations

FirestoreException (com.google.cloud.firestore.FirestoreException)1 ListenerRegistration (com.google.cloud.firestore.ListenerRegistration)1 Query (com.google.cloud.firestore.Query)1 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)1