Reputation: 33
I'm trying to implement a location live tracking on my Android app using https://developer.android.com/training/location/index.html. The thing is that I would like to use a background process to do all the work and I have several doubts about which implementation should I use.
As far as I'm concerned Android Service
class creates a background service which can be attached to an Activity or be independent. The downside of this implementation is that the service can be killed by the system in case it needs to free resources. My question here is, does the service run even if the app is closed?
On the other hand, Android JobScheduler
class provides a batch scheduler which only runs when the job needs to be done, avoiding system kills. But it seems that the scheduler keeps running even after closing the app (which is not desired as I just want the tracking service to be running while the app is active or in background).
I would go for the JobScheduler as it consumes way less resources and avoids getting killed by the system, but it runs even after the app is closed which is not desired. Which of them should I use? Feel free to comment any other implementations.
Thanks in advance.
Upvotes: 2
Views: 415
Reputation: 35
Implementing Location Tracking can be done by integrating Teliver SDK. Live Tracking made easier
Teliver SDK is wrapped up with a code that runs a background service to update location values for a Interval in a Operator device and in another device which act as a Reciever will reveive the location values of a particular operator and plot the location in Maps.
STEP 1: Intialize Teliver in your Application...
Teliver.init(this,"TELIVER_KEY");
"TELIVER_KEY" is to identify your application that you get from Teliver Dashboard.
STEP 2: Now you can start to transmit the location in a device that has to be Tracked,by the following code.
Teliver.startTrip(new TripBuilder("Tracking_Id").build());
Now the device is started to Transmit Location,a foreground service is created that updates location even your app is running in background..
STEP 3: you can stop transmitting the location anytime by the below snippet of code.
Teliver.stopTrip("Tracking_Id");
The Tracking_Id is a identifier key to spot the particular Transmitting Device.
STEP 4: To Track a device that is Transmitting location use the Teliver SDK method.
Teliver.startTracking(new TrackingBuilder(new MarkerOption("Tracking_Id")).build());
With the above code samples you can easily run a background service class that updates a device location and also receive the location values and show the exact location of the transmitter in Maps
Upvotes: 2