@@ -54,6 +54,7 @@ Map<String, Object> listenToDocument() throws Exception {
5454 final SettableApiFuture <Map <String , Object >> future = SettableApiFuture .create ();
5555
5656 // [START listen_to_document]
57+ // [START firestore_listen_document]
5758 DocumentReference docRef = db .collection ("cities" ).document ("SF" );
5859 docRef .addSnapshotListener (new EventListener <DocumentSnapshot >() {
5960 @ Override
@@ -76,6 +77,7 @@ public void onEvent(@Nullable DocumentSnapshot snapshot,
7677 // [END_EXCLUDE]
7778 }
7879 });
80+ // [END firestore_listen_document]
7981 // [END listen_to_document]
8082
8183 return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -88,6 +90,7 @@ List<String> listenForMultiple() throws Exception {
8890 final SettableApiFuture <List <String >> future = SettableApiFuture .create ();
8991
9092 // [START listen_to_multiple]
93+ // [START firestore_listen_query_snapshots]
9194 db .collection ("cities" )
9295 .whereEqualTo ("state" , "CA" )
9396 .addSnapshotListener (new EventListener <QuerySnapshot >() {
@@ -113,6 +116,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
113116 // [END_EXCLUDE]
114117 }
115118 });
119+ // [END firestore_listen_query_snapshots]
116120 // [END listen_to_multiple]
117121
118122 return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -125,6 +129,7 @@ List<DocumentChange> listenForChanges() throws Exception {
125129 SettableApiFuture <List <DocumentChange >> future = SettableApiFuture .create ();
126130
127131 // [START listen_for_changes]
132+ // [START firestore_listen_query_changes]
128133 db .collection ("cities" )
129134 .whereEqualTo ("state" , "CA" )
130135 .addSnapshotListener (new EventListener <QuerySnapshot >() {
@@ -158,6 +163,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
158163 // [END_EXCLUDE]
159164 }
160165 });
166+ // [END firestore_listen_query_changes]
161167 // [END listen_for_changes]
162168
163169 return future .get (TIMEOUT_SECONDS , TimeUnit .SECONDS );
@@ -168,6 +174,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
168174 */
169175 void detachListener () {
170176 // [START detach_errors]
177+ // [START firestore_listen_detach]
171178 Query query = db .collection ("cities" );
172179 ListenerRegistration registration = query .addSnapshotListener (
173180 new EventListener <QuerySnapshot >() {
@@ -184,6 +191,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
184191
185192 // Stop listening to changes
186193 registration .remove ();
194+ // [END firestore_listen_detach]
187195 // [END detach_errors]
188196 }
189197
@@ -192,6 +200,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
192200 */
193201 void listenErrors () {
194202 // [START listen_errors]
203+ // [START firestore_listen_handle_error]
195204 db .collection ("cities" )
196205 .addSnapshotListener (new EventListener <QuerySnapshot >() {
197206 @ Override
@@ -209,6 +218,7 @@ public void onEvent(@Nullable QuerySnapshot snapshots,
209218 }
210219 }
211220 });
221+ // [END firestore_listen_handle_error]
212222 // [END listen_errors]
213223 }
214224
0 commit comments