How to implement Firebase Recycler Adapter in newer version of Android 3.1 and higher?

前端 未结 2 1476
旧巷少年郎
旧巷少年郎 2020-12-18 09:05

Basically, what I am trying to do is use a FirebaseRecyclerAdapter and populate the RecyclerView with my custom designed CardView. The

2条回答
  •  一个人的身影
    2020-12-18 09:23

    In order to be able to display data from the Firebase realtime database you need to start listening for changes and for that you should add the following line of code in the onStart() method:

    @Override
    protected void onStart() {
        super.onStart();
        FBRA.startListening();
    }
    

    To stop listening foir changes you need add the following line of code in the onStop() method like this:

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

    Please see my answer from this post where I have explained why you should remove the listener.

    P.S. Please also don't forget to make the FBRA a global variable and remove FirebaseRecyclerAdapter from the declaration of the object.

提交回复
热议问题