Recognizing Android activity with a listener or broadcast receiver?

I am wondering why ActivityRecognitionClient has no way to request updates with a standard java listener as a parameter? It is more strange that at the same time, LocationClient has such a method , and it works well.

The official example for Activity Recognition looks awful. A lot of related and boilerplate codes. It seems that IntentService is the only option for handling updates from ActivityRecognitionClient. It is very uncomfortable.

@Guys from the Android group, why is this happening?

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

So far, does anyone know if it is possible to use BroadcastReceiver to handle updates from an ActivityRecognitionClient?

+4
source share
1 answer

I am wondering why ActivityRecognitionClient has no way to request updates with a standard java listener as a parameter?

Many good questions give rise to a certain opinion based on expert experience, but the answers to this question will, as a rule, be almost entirely based on opinions, and not on facts, links or specific experience.

Also, citing the documentation for requestActivityUpdates() :

A common use case is that the application wants to track actions in the background and take action when a specific action is detected. To do this, without requiring a service that is always in the background resource consumption, the detected actions are delivered with intent. An application defines a PendingIntent callback (usually an IntentService) that will be called when actions are detected.

It seems that IntentService is the only option for handling updates from ActivityRecognitionClient.

This is not true.

So far, does anyone know if it is possible to use BroadcastReceiver to handle updates from an 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 can use any other PendingIntent , for example, one of getBroadcast() , which is called sendBroadcast() .

+4
source

Source: https://habr.com/ru/post/1489452/


All Articles