To solve this, first make your adapter variable global:
private FirebaseRecyclerAdapter<UserInformation, EmployeeViewHolder> adapter;
Then you need to add the following lines of code in your onStart()
and onStop()
methods:
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
if(adapter != null) {
adapter.stopListening();
}
}
Because the adapter uses a listener to check for database changes, in order to make it work, we need to start listening first. And when we close the application, we need to stop listening.
I have explained in one of my videos, how to achieve this, step by step.