Reputation: 3329
I plan to program an Android app that periodically determines the device's position (say every five minutes) and uploads position data to the internet. The tracking shall be explicitly activated and deactivated by the user and shall go on when the user leaves the application (activity) or the device switches to standby. The upload of position data to the internet does not have to be realtime, but should happen soon.
I already read the Android Dev Guide about services and obtaining user location as well as some howtos about creating a service. As far as I got it, I should implement a (foreground-)service to get the location and temporarily save it somewhere. Another service would care about uploading the data.
But there are still a lot of things I'm not shure about: Should I use a thread and a loop with a timer? Or an IntentService and then trigger an Intent every 5 minutes (how, where)? Or use AlarmManager? And how can I trigger the upload of the position data?
I am fairly new to all this (I only created some desktop Java programs yet), and I would be very happy if someone gave me an idea how to implement this in Android.
Thanks!
Upvotes: 0
Views: 270
Reputation: 3282
You should set an Alarm via Alarm Manager to start the service. The service then should look for location, and send it to the final destination.
I would also implement a second thread in the service that pauses for a time (say 15 seconds) and terminates the service. Otherwise if no location can be found for some reason, you will destroy the devices batteries by continuously looking.
Upvotes: 1