Android的ActivityRecognitionApi requestActivityUpdates过于频繁。我该如何节流呢? [英] Android ActivityRecognitionApi requestActivityUpdates are too frequent. How can I throttle them?
问题描述
我想改变我经常要求根据用户的活动级别从FusedLocationProviderAPI位置更新。 Android提供了一个ActivityRecognitionApi这将是巨大的,但遗憾的是:
I'm trying to change how often I request location updates from the FusedLocationProviderAPI based on the activity level of the user. Android provides an ActivityRecognitionApi which would be great, but unfortunately:
的活动可被更频繁地比detectionIntervalMillis参数接收如果另一应用程序已经以更快的速度也要求活动更新。 (来源:<一个href=\"https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html\" rel=\"nofollow\">https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html)
"Activities may be received more frequently than the detectionIntervalMillis parameter if another application has also requested activity updates at a faster rate." (From: https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html)
我想没有更多的时候执行code比一次,比如说10秒。什么是做到这一点的最好方法是什么?
I'd like to execute code no more often than once every, say, 10 seconds. What's the best way to do this?
推荐答案
您可能已经找到了解决方案现在,但..
You have probably found a solution by now, but..
I am currently working on a fork of https://github.com/mcharmas/Android-ReactiveLocation trying to add Activity Recognition. Using an RxJava observer, you easily define a filter that only let new activities go to the subscribe() method if x seconds has passed.
叉可以在这里找到: https://github.com/cyrixmorten/Android-ReactiveLocation一>
这篇关于Android的ActivityRecognitionApi requestActivityUpdates过于频繁。我该如何节流呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!