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

◇◆丶佛笑我妖孽 提交于 2019-11-30 13:17:48

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.

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;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!