0

I'm using activity recognition api and location using google play services and I'm aware of how battery consuming they are so I would actually be pleased if this is the case and the Job Service stops when the screen is on which limits the collection of data to when the user is actually using his phone and not 24/7.

When I tried testing this, sometimes it stops after half an hour, sometimes more and at times it happens immediately so is this related to other background services and the current apps that are being used ? and is there a way to force the service to stop when the screen is off ?

As for the code I'm using the exact sample that I downloaded from the repository and the only modification that I made was calling the recognition service from the job service whenever the service is triggered (periodic task)

student93
  • 307
  • 2
  • 12

1 Answers1

0

If I am understanding correctly, you have a JobDispatcher which repeatedly schedules the job to run after a fixed amount of time. If that's the case, then you do have the option to set the job to only run when the device is in idle or charging state.

This behaviour can be set with the JobInfo object that is passed to the JobScheduler.schedule(JobInfo job) method.

You can look at the documentation for JobInfo for refrence: https://developer.android.com/reference/android/app/job/JobInfo.html

  • I know about the charging state and that doesn't help me because I want to get the user's location and activity while he is on the move (requiring charging restricts that) and as for idle, it means the service would only run when the screen is off, that isn't what I want either. I want the opposite (the service to stop running when the device is idle in order to reduce battery consumption.) – student93 Mar 02 '17 at 19:06
  • I would like to note that I want to do this because phones are idle more than awake most of the time so I want to reduce the consumption by pausing the service when the device is idle – student93 Mar 02 '17 at 19:12