views:

29

answers:

1

I have few questions about getting current location of the device.

I believe only way to do that is using requestLocationUpdates(....).

  1. if I subscribe to requestLocationUpdates... with duration set to 1 hour and after 1 hour if my phone is sleeping (or during that 1 hour I rebooted my phone), does the listener still work?

A. If yes... . After 1 hour, when I get update about location, I want to change duration to 2 hours. Is there a way to do that? If not, can I call removeUpdates, and immediately call requestLocationUpdates with duration as 2 hours?

B. If No... I was planning to set an alarm to go off after 1 hour, and call removeUpdates & requestLocationUpdates in the alarm receiver. Is that right strategy.

A: 

I'm not 100% sure but If you reboot your phone service isn't started again, also as is written in a manual:

minTime - the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.

This is only a hint for update time but it's not reliable. Your practice should be to make a Service which should use Handler and postDelayed to set timed action within a runnable. I hope I helped.

dfilkovi