I have to send my current location details (lat & long) to server periodically (Ex: for every 5 minutes). Is there any best way? I know how to get the current location & how to send the details to server. But how do I repeat this in periodic intervals?
Share
Register an alarm using
AlarmManagerto wake up after 5min when user open the application first time. create a service(fetch location and update to server) to run when alarm notifies your application. After the service finished the work , register for an alarm again to wake up after 5min. by this way you can achieve your task.ref
Android: How to periodically send location to a server
http://developer.android.com/reference/android/app/AlarmManager.html
http://developer.android.com/reference/android/app/Service.html
1st Edit – Adding code sample
Step 1 – Create alarm manager and register alarm
Step 2 – Create Receiver class
Setp 3 – Create Service class
Step 4 – Register service and receiver
Note : This code is to understand the implementation. It will not compile.