I am making a chat app on Android that uses google firebase to store messages that users write to each other. To display these messages to the users I read them from the dat
You need to use this:
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
Since FirebaseListAdapter
uses a listener to check for changes in the firebase database, then to being listening for data you need to add adapter.startListening()
inside the onStart()
to be able to show the data in the listview.
Then inside onStop()
(when activity is stopped), you can use adapter.stopListening()
to remove the listener and the data in the adapter.
Check this for more info: Adapter LifeCycle
If after using the above, you get a nullpointexception
or cannot resolve symbol
, you have to declare adapter
as global variable and please check the below answer: Error in startListening()