Search code examples
androidlocationmanager

Can LocationManager "wake-up" my application same as AlarmManager does it?


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.


Solution

  • 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.