Update GPS Listener every 5 seconds

后端 未结 2 788
心在旅途
心在旅途 2021-01-23 09:31

I\'m supposed to update the listener every 5 seconds. But it doesn\'t. What could be wrong with my code?

Thanks a lot for any help!

package com.example.a         


        
2条回答
  •  不思量自难忘°
    2021-01-23 10:12

    By setting it to 5000 ms it doesn't necessarily mean that you will get the location every 5th second. The time is more or less a best case scenario.

    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. http://developer.android.com/reference/android/location/LocationManager.html

    Are you sure you have your activity running? If you want to recieve the location when the activity is sleeping you need a wake lock and a service.

    For example in a GPS app I created I put 0 ms to get it as soon as possible but when debugging and checking the logcat I sometimes get the location every minute or so, not every second.

提交回复
热议问题