I am developing simple text messaging app using FCM (latest GCM), where I have an activity called ChatActivity that shows list of messages using ListView.
However, when any new message arrives it will be handled by FirebaseMessagingService class...
public class MyFcmListenerService extends FirebaseMessagingService {
@override
public void onMessageReceived(RemoteMessage remoteMessage) {
String from = remoteMessage.getFrom();
Map<String, String> data = remoteMessage.getData();
String body = rawData.get("body");
Log.i("From",from);
Log.i("Message",body);
}
}
This class prints message in console successfully whenever any new message arrives.
My question is, when I get a new message from FCM in onMessageReceived() class, how can I add that String message to the ListView in ChatActivity ?
And, after adding item to the ListView, how can I call .notifyDataSetChanged() on ListView Adaptor ?