Skip to content Skip to sidebar Skip to footer

Managing The Android Back Stack And Listeners With Firestore For Optimizing Document Reads

I have activity A and activity B in Android. In activity A there are a FirestoreRecyclerAdapter and a FirestoreRecyclerOptions object, which update in realtime a RecyclerView. I st

Solution 1:

When you are using Query's addValueEventListener() method, you should remove the listener according to the life-cycle of your activity, as explained in my answer from the following post:

If you are using the Firebase-UI library, once you start listening for changes in your onStart() method:

@OverrideprotectedvoidonStart() {
    super.onStart();
    firestoreRecyclerAdapter.startListening();
}

You also need to stop listening for changes in onStop() method:

@Override
protected void onStop() {
    super.onStop();
    if(firestoreRecyclerAdapter != null) {
        firestoreRecyclerAdapter.stopListening();
    }
}

Post a Comment for "Managing The Android Back Stack And Listeners With Firestore For Optimizing Document Reads"