问题
I write an android app.
I want to send the server the user's location every 5 minutes even if he hasn't moved.
how would you suggest me to do it?
Using a Timer and just sending the location every 5 min
or using locationListener with minDistance = 0 m and minTime = 5 min?
回答1:
Write a AlarmManager
that would wake up every 5 minutes and use LocationListener
to get the current location to send to server. After sending location updates, just unregister(remove updates) the locationListener. In this way, you will be improving the battery performance. Imagine the case where your locationListener
keeps running in the background.
来源:https://stackoverflow.com/questions/22279059/how-to-notify-the-server-every-5-minutes-on-users-location