android - FirebaseRecyclerAdapter not updating data automatically -
i using firebaserecycleradapter comes firebaseandroid-ui library , assume when data change on firebase automatically refresh , update recyclerview.
my code simple:
firebase firebasepicturesref = new firebase(firebase_url); madapter = new firebaserecycleradapter<image, imageviewholder>( image.class, r.layout.pictures_grid_item, imageviewholder.class, firebasepicturesref) { @override protected void populateviewholder(imageviewholder viewholder, image model, int position) { super.populateviewholder(viewholder, model, position); glide.with(getactivity()).load(model.getthumbnailurl()).into(viewholder.mimageview); } }; i have tried manually refresh adapter using notifydatasetchanged in the ondatachange method:
firebasepicturesref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { if (madapter != null) madapter.notifydatasetchanged(); } @override public void oncancelled(firebaseerror firebaseerror) { } }); am doing wrong? fix?
i found problem, calling madapter.cleanup(); in onstop() of fragment. removing fixed problem.
instead of doing cleanup in onstop(); should called in ondestroy()
as suggested frank:
in general should call cleanup() in "opposite" method create adapter. oncreate()<->ondestroy(), onstart()<->onstop(), onpause()<->onresume()
Comments
Post a Comment