3

my application collects periodically Activity Recognition's Detected activity data. I implemented it exactly as described in the documentation , but with one minute interval.

as long as the user is logged in - the application registered with a PendingIntent to receive updates from google play process..

please not lecture me about battery usage, network, and performance problem derived from request updates each minute, unless it have something to do with my problem:

the problem: in some devices (in Nexus 5 it happens the most), for a 5-6 hours in the middle of the night - the IntentService stopped been called.

I'm not sure, but suspects it have something to do with Google optimizations and the significant motion sensor not detecting any motion entering the activity recognition mechanism to be in sort of idle mode, as described in the documentation that can happened.

it's important to my app to know what is the current activity each minute approximately even if it stay the same, or idle for a long time..

my question:

  • how can I know if the periodically activity recognition stopped been called because of the significant motion sensor or from any other reason?
  • it there a way to force somehow the Google play process to perform activity updates without stop it for a time it assumes not needed?
Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • Hello have you get any best solution for same actually my app also need to store each activity data to our backend. can you help me with better solution – Vishal Thakkar Mar 15 '19 at 10:12

1 Answers1

4

Per ActivityRecognitionClient.requestActivityUpdates:

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.

As you suspected. There's no reason you cannot save the last value using the many data storage techniques - a simple SharedPreference might be enough for your case.

If you are directly triggering actions based on the IntentService being called (a bad idea since other apps may cause it to trigger extremely quickly) rather than only on changes in activity, then you should decouple those actions and instead set an alarm or trigger a periodic sync adapter for whatever specific time interval you need, reading the current value from the last activity you received.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • thanks for the fast response. in the activity recognition update IntentService all I'm doing is store the DetectedActivity into SQLite database. I did not understand what you ment about decoupuling. decouple between what to what? – Tal Kanel Jun 12 '14 at 06:51
  • So if you are already storing the activity, then you always know the latest activity (activity with the highest timestamp) so what's the problem? For decoupling I meant if you were triggering network requests or something more heavyweight. – ianhanniballake Jun 12 '14 at 06:56
  • I need to record minute by minute data all the time. record = store in database, and sync once in a time with my server. so if it stopped for 4-5 hours, it's not good for my needs... – Tal Kanel Jun 12 '14 at 06:58
  • Right, but you're already not guaranteed minute by minute data - if another app requests updates every second, then you'll also get called back at that same rate rather than only once a minute. – ianhanniballake Jun 12 '14 at 17:31
  • If you need to strictly store data every minute, do so even if you don't get anything from google's activity service. You'll just need to persist the latest value you got from Google and send it over and over again. You'll end up with a lot of redundant data though. – Jose L Ugia Jun 22 '14 at 10:46