My app is supposed to track airplanes on a map using data streamed over the Internet. I use a Service to receive the data, and then I use Messengers to send messages between it and my MainActivity (thanks to this guide), which has my Fragment with a SupportMapFragment (MainMapFragment) and also a RecyclerView Fragment (AircraftListFragment).
Each Marker is in a HashMap with an Aircraft object in MainMapFragment, and the Aircraft objects are maintained by the MainActivity. Is there anything like notifyDatasetChanged() for my Activity to update my MapFragment? Obviously I can't write a method in MainMapFragment like this:
public void updateAircraftArrayList(ArrayList<Aircraft> updatedAircrafts){
this.aircraftArrayList = updatedAircrafts;
updateMarkers(); //Update the Markers on the map
}
accessed like this in my MainActivity:
class IncomingHandler extends android.os.Handler {
@Override
public void handleMessage(Message msg){
String aircraftMsg = msg.getData().getString("fromSocket");
Aircraft newAircraft = decodeSbsMessage(aircraftMsg);
aircraftArrayList = searchThroughArrayListForAircraft(newAircraft);
MainMapFragment.updateAircraftArrayList(aircraftArrayList);
}
}
I've heard of EventBus, but from what I've heard it's not very good for handling a constant stream from a Socket.