Domanda

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?).

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top