我想知道,为什么 ActivityRecognitionClient 没有方法以标准 java 监听器作为参数来请求更新?更奇怪的是,同时 LocationСlient 有 such method效果很好。
Official example Activity 识别看起来很糟糕。很多耦合和样板代码。看起来 IntentService 是处理来自 ActivityRecognitionClient 的更新的唯一变体。这非常不舒服。
@Android 团队的伙计们,为什么会这样?
作为开发者,我希望在下一版本的 Google Play 服务中看到 requestActivityUpdates(interval, listener) 方法。
目前,有谁知道是否可以使用 BroadcastReceiver 来处理来自 ActivityRecognitionClient 的更新?
最佳答案
I'm wondering, why ActivityRecognitionClient has no method to request updates with standard java listener as parameter?
许多好的问题会产生某种程度的基于专家经验的意见,但这个问题的答案往往几乎完全基于意见,而不是事实、引用或特定专业知识。
除此之外,引用 the documentation对于 requestActivityUpdates()
:
A common use case is that an application wants to monitor activities in the background and perform an action when a specific activity is detected. To do this without needing a service that is always on in the background consuming resources, detected activities are delivered via an intent. The application specifies a PendingIntent callback (typically an IntentService) which will be called when activities are detected.
It looks like IntentService is sole variant for handling updates from ActivityRecognitionClient.
不是。
For now, does anyone know, is it possible to use BroadcastReceiver for handling updates from ActivityRecognitionClient?
PendingIntent
有多种类型,由各种工厂方法创建。该示例显示使用 getService()
创建将调用 startService()
的 PendingIntent
。欢迎您使用任何其他 PendingIntent
,例如 getBroadcast()
中的一个,它将调用 sendBroadcast()
。
关于使用监听器或广播接收器进行 Android Activity 识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17445765/