简体   繁体   中英

Run AsyncTask every X second to update GPS position

I have a class that extends AsyncTask , which fetches the gps cordinates from the device.

I would like to keep the data updated, so my initial though was to call the class from a timer or a handler. Is this a smart way to implement it, or am i better off listening to the onLocationChanged and do my updates in there?

Hope you get the idea, otherwise ill elaborate.

Thanks!

An alarmManager will be a good solution here.

These allow you to schedule your application to be run at some point in the future.

When an alarm goes off, the Intent that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running.

So when alarm gets triggered, call your execute() method of Async task.

For more info see this: http://developer.android.com/reference/android/app/AlarmManager.html

I also want to implement the same in my app in near future. If you get the solution, don't forget to update the post about how you implemented it.

Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM