Update GPS Listener every 5 seconds

后端 未结 2 793
心在旅途
心在旅途 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

    As stated by David Olsson, MINIMUM_TIME_BETWEEN_UPDATES only prevents the listener to be requested too often. If you want to regularly requestLocationUpdates, you should use Timer and TimerTask and have requestLocationUpdates run once every 5 seconds

    schedule(TimerTask task, long delay, long period)
    Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay.
    

提交回复
热议问题