Search code examples
androidserviceandroid-servicelocationmanagerlocationlistener

LocationManger only gives me one update


What I'm trying to do


Hello Guys, I'm trying to create a service which post every hour a Locationupdate to my Server. The Code seems to work, when I start the Service, It automaticly posts the first locationupdate, afterwards nothing happens. But the strange thing is, sometimes it does sometimes not ...

Question


So what do I need to change in my code that my locationmanager puts every hour a locationupdate. If you have a great tutorial or some codesamples it would be great!


Solution

  • Probably your device turned of the CPU to save battery power and your service will not receive an update. Consider using an alarm for the updates, which just requests one location update (there is a method for in the location manager this since API 9) or use the WakeLock in your service (which is a waste of battery power if you need just one update every hour).

    See here for more info on the alarm manager: http://developer.android.com/reference/android/app/AlarmManager.html