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

无人久伴 提交于 2019-11-29 07:59:01

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<ServiceClass, ServiceViewHolder> from the declaration of the object.

This is more of an advice. If you want to continue using the old method to populate your recyclerview ie The "populateViewHolder" method instead of the new "onBindViewHolder" method just use this;

implementation 'com.firebaseui:firebase-ui:1.0.1'

instead of upgraded firebase-ui versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!