In my app I have a Service
which receives location updates and stores them to a database. I also have a Fragment
which displays a MapView
and a PolyLine
of all recorded waypoints from the database.
During recording, the Service
notifies the Fragment
about new waypoints so the Fragment
can update the PolyLine
. The problem is that when the user navigates away from the app the app the Service
keeps recording waypoints to the database, but now the Fragment
doesn't get updated since the Fragment
is paused. So in onResume
I create a new PolyLine
, read all the waypoints in the database and add them to the database.
This is all working fine, but it doesn't really feel like it's optimal from a performance perspective to create a new PolyLine
and re-add all the waypoints (there could be thousands!). I guess I could just re-add any new waypoints that are not already in the PolyLine
, but I wanted to see if anyone here has an alternate solution? Is there any way to keep the Fragment
"alive" and updating its PolyLine
even when the app is in the background (as long as the service is running)? Or is there a better way to do this?