android – Is there a way to clear a firebase recycler adapter so that it again loads new data-ThrowExceptions

Exception or error:

Everytime when the onResume() method is called the adapter contains duplicate data in the recycler view. I wanted to clear the list everytime the onResume() method is called and again fetch the new data is this possible ?

My code structure looks like this

@Override
    protected void onStart() {
        super.onStart();

        ...

        recyclerView.setAdapter(adapter);
        adapter.startListening();
    } 

@Override
    protected void onStop() {
        super.onStop();
        adapter.stopListening();
    }

@Override
    protected void onResume() {
        super.onResume();
        adapter.startListening();
    }
How to solve:

Try below code:

@Override
    protected void onResume() {
        super.onResume();
       adapter.notifyDataSetChanged();
  }

Leave a Reply

Your email address will not be published. Required fields are marked *