1

Background: My application should get its geographical location every X seconds, send the location to server. The server responds with new interval X' and from now on the application should get its geographical location every X' seconds and so on. The application should run indefinitely.

Question: AlarmManager can execute my application code at a specific time, even if my application is not currently running. Can LocationManager do the same or I should keep my service running in background and "recreate" every time the OS kills it? This article advocates the former approach but I'm not sure I can implement it with LocationManager.

Lopotun
  • 611
  • 7
  • 15

2 Answers2

0

You need to create a service that implements "onlocationchanged" listener

Chet
  • 1,205
  • 1
  • 12
  • 20
0

you can define a BroadcastReceiver with an AlarmManager that uses AlarmManager.ELAPSED_REALTIME_WAKEUP Check this answer: https://stackoverflow.com/a/7709140/779408

there is a solution there.

Community
  • 1
  • 1
Bob
  • 22,810
  • 38
  • 143
  • 225
  • Ah, sorry. I should have mentioned in the question that the application should get its geographical location also every Y meters, not only every X seconds. So, the "wake-up" should be based both on time and distance. – Lopotun Sep 20 '12 at 10:11