Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity Recognition with listener or broadcast receiver?

I'm wondering, why ActivityRecognitionClient has no method to request updates with standard java listener as parameter? More strange, that in the same time, LocationСlient has such method and it works good.

Official example for Activity Recognition looks terrible. A lot of coupled and boilerplate code. It looks like IntentService is sole variant for handling updates from ActivityRecognitionClient. It's extremely uncomfortable.

@Guys from Android Team, why it happens?

As Developer I hope to see requestActivityUpdates(interval, listener) method in next version of Google Play Services.

For now, does anyone know, is it possible to use BroadcastReceiver for handling updates from ActivityRecognitionClient?

like image 593
AlexKorovyansky Avatar asked Jul 03 '13 10:07

AlexKorovyansky


1 Answers

I'm wondering, why ActivityRecognitionClient has no method to request updates with standard java listener as parameter?

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.

Beyond that, quoting the documentation for 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.

It's not.

For now, does anyone know, is it possible to use BroadcastReceiver for handling updates from ActivityRecognitionClient?

There are several types of PendingIntent, created from various factory methods. The sample shows using getService() to create a PendingIntent that will call startService(). You are welcome to use any other PendingIntent, such as one from getBroadcast(), which will call sendBroadcast().

like image 194
CommonsWare Avatar answered Sep 21 '22 19:09

CommonsWare