Question

I am trying to code a service that repeatedly checks user location, but shuts off if certain things don't occur within about 3 minutes. I put the shut-the-service-off-logic in onLocationChanged. I just realized that if a user puts a phone on a table and leaves it there onLocationChanged may never be called, and the shutoff logic will never be entered. Is there some other method that could be overridden that gets called every time location is requested? Do I need to manually call onLocationChanged (and is that even a good idea?).

Was it helpful?

Solution

Create a CountdownTimer and set the millisInFuture to 3 minutes. In onFinish() of the timer removeLocationUpdate. Start this timer when you requestLocationUpdate and cancel and start the timer again in onLocationChanged.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top