Difference between LocationRequest setInterval (long millis) and LocationRequest setFastestInterval (long millis)

前端 未结 4 1850
一个人的身影
一个人的身影 2021-01-31 06:52

I am writing my own background location updates for interval of every 5 minutes in android. I would like to know the difference between setInterval and setFastestInterval

4条回答
  •  無奈伤痛
    2021-01-31 07:29

    Based on the relevant Android documentation:

    • setInterval(long) means - set the interval in which you want to get locations.
    • setFastestInterval(long) means - if a location is available sooner you can get it (i.e. another app is using the location services).

    For example, you start your application and register it via setInterval(60*1000), that means that you'll get updates every 60 seconds.

    Now you call setFastestInterval(10*1000). If you are the only app which use the location services you will continue to receive updates approximately every 60 seconds. If another app is using the location services with a higher rate of updates, you will get more location updates (but no more frequently that every 10 seconds).

    I believe that it has a good impact on battery life consumed by your app, you define the maximum amount of time that you can wait while saying that if an update is available, you want it. The battery consumption will be credited to the app which requested the more frequent updates and not yours.

提交回复
热议问题