2

I'm testing Activity Recognition API in 2 apps : Google sample code and implementation of this code in my app.

The problem is both apps keeps getting activity recognition fine but after a few hours the intent service stops and i'm not getting any activity recognition from both of them.

Any idea why the intent service stops even though i've tested geofencing api with intent service and it's working forever without stopping?

WoW
  • 151
  • 2
  • 10
  • What are you using as an intent target? IntentService? Something else? – dragoon May 20 '15 at 18:24
  • 1
    I saw somewhere on SO that IntentService eventually goes away if the app is destroyed. Try using an intent for a normal Service, or WakefulBroadcast and then IntentService. – dragoon May 20 '15 at 18:32
  • Thanks for the advice ! I've tryied already activity recognition with intent service and it looks like it's working the problem is when you update/reintall the app .. sometimes you need to reboot the device to make it work again. I thought about converting the intent service to a service – WoW May 20 '15 at 19:20

2 Answers2

4

Your IntentService might "stop", I would say "fall asleep" because of:

To conserve battery, activity reporting may stop when the device is 'STILL' for an extended period of time. It will resume once the device moves again. This only happens on devices that support the Sensor.TYPE_SIGNIFICANT_MOTION hardware.

Basically it should be the case for most of the devices with API >= 20.

Please find more here.

Unfortunately, you can only request activity updates and it is impossible to force ActivityRecognitionApi to continuously give current activity even if it is "still" for some mysterious "extended period of time".

In my opinion, it would much more convenient if this feature of ActivityRecognitionApi was configurable.

mibrl12
  • 454
  • 5
  • 21
  • Thanks for the answer! after lots of tests i made with ActivityRecognitionApi it looks like it's not always stable. Sometimes it's working continuously and after a while it's "falling a sleep" . – WoW Oct 07 '15 at 20:23
  • In my case it stop reporting even after device start moving and sometime it gives me update regularly even when device is still. It should start back when activity state change but its not sometime.You right it would be easier if we can config API settings. – androidXP Apr 30 '17 at 12:29
0

Even registering broadcast receiver in Manifest file,you need to register in dynamically in Oreo+ otherwise it will not work. Try this.Add this code in main activity or in startCommand in Service.It worked for me.I have tested this code on Android 10 too..worked perfectly.You need not to register broadcast receiver in Manifest file.

@Override
    protected void onStart() {
        super.onStart();
        IntentFilter intentFilter=new IntentFilter(Constants.BROADCAST_DETECTED_ACTIVITY);
    intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
        registerReceiver(broadcastReceiver,intentFilter);

    }
jyotsna
  • 97
  • 1
  • 9