14

While converting an app to be ready for Android Oreo, I read the docs on JobIntentService over here.

In there I find (important part emphasised):

When running as a pre-O service, the normal service execution semantics apply: [...] When running as a Job, the typical JobService execution time limit will apply, after which the job will be stopped (cleanly, not by killing the process) and rescheduled to continue its execution later.

If I look at the documented limitations there is no word about any execution time limits. Also JobScheduler does not mention anything.

  • Is this a time limit I should simply not be concerned about?
  • Is it undocumented?
  • Or is the execution time limit not/no longer existing?
  • Or will I have to redesign my services in a way that they can be interrupted and restarted at any given point in time? Best practices?

2 Answers 2

14

How long is the “JobService execution time limit” mentioned in Android's JobIntentService docs?

In practice, it seems to be 10 minutes. I originally determined that by testing, but IIRC somebody pointed out the limit in the source code.

Is this a time limit I should simply not be concerned about?

If you are really sure that your work will be done in less time, yes, at least for the time being.

Is it undocumented?

Yes.

Or is the execution time limit not/no longer existing?

It existed the last time I tested it.

Or will I have to redesign my services in a way that they can be interrupted and restarted at any given point in time?

Well, ideally, yes, particularly if you are using any constraints beyond time. For example, if you say that your job requires a network connection, and the device loses connectivity, your job will be stopped. That could occur well before the 10-minute time period elapses.

Best practices?

Avoid periodic background work to the greatest extent possible.

3
  • The short version of this answer for coders familiar with iOS: about the same restrictions apply. :-)
    – Krumelur
    Feb 6, 2018 at 7:44
  • As per online documentation, after typical JobService execution time limit, the job will be stopped (cleanly, not by killing the process) and rescheduled to continue its execution later.Since it says rescheduled to CONTINUE it's execution later, I would assume any job which is beyond 10 mins will also be respectfully finished, though in slots Aug 23, 2018 at 18:35
  • 2
    I don't understand a definition "stopped (cleanly, not by killing the process)", if you are doing some operation like syncing data from the server and storing it to the database, how you will be clearly informed that you should stop doing it? If you will have forech cycle there, there is no way how to stop it cleanly.
    – ATom
    Mar 8, 2019 at 17:28
1

In order to avoid execution time limit i use bellow practice it solve my problem.

@Override
    public void onDestroy() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isStopped()) {
           //do nothing
        } else {
            super.onDestroy();
           //on destroy called
        }
    }

    @Override
    public boolean onStopCurrentWork() {
        return false;
    }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.