Managing the Android back stack and listeners with Firestore for optimizing document reads

前端 未结 1 1984
我寻月下人不归
我寻月下人不归 2021-01-17 04:46

I have activity A and activity B in Android.

In activity A there are a FirestoreRecyclerAdapter and a FirestoreRecyclerOptions object, whic

相关标签:
1条回答
  • 2021-01-17 05:32

    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:

    • Should I actually remove the ValueEventListener?

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

    @Override
    protected void onStart() {
        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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题