I'd like to upload the current user's location about every 2 minutes when device is awake, or about every 5 minutes when not.
What would be the best way to upload the data in the background (even if app is not running) to a web server? Is an IntentService
with AlarmManager
or something like an AsyncTask
with a CountdownTimer
better?
I already know how to get a user's location, and have some practice with AsyncTask
and IntentService
. Any help would be appreciated! Thanks!
There are two better ways that will help you:
1. When app is awake
You can use handler for timer purpose and from the handle call IntentService for location update.
IntentService
will work in differentThread
and will finished itself after work completion. Handler Example
2. When app is not running
You have to use
AlarmManager
and from the Alarm Receiver you will call IntentService for location update. AlarmManager Example
Hope it will help you.