how to notify the server every 5 minutes on user's location?

扶醉桌前 提交于 2019-12-11 12:57:27

问题


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 LocationListenerto 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!