Android 的 JobIntentService 文档中提到的 "JobService execution time limit" 有多长?
How long is the "JobService execution time limit" mentioned in Android's JobIntentService docs?
在为 Android Oreo 准备应用程序时,我阅读了 JobIntentService
over here.
上的文档
在那里我发现(强调了重要部分):
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.
如果我看 documented limitations there is no word about any execution time limits. Also JobScheduler
does not mention anything.
- 这是我不应该关心的时间限制吗?
- 它没有记录吗?
- 或者执行时间限制 not/no 是否更长?
- 或者我是否必须以可以在任何给定时间点中断和重新启动的方式重新设计我的服务?最佳做法?
How long is the “JobService execution time limit” mentioned in Android's JobIntentService docs?
实际上好像是10分钟。我最初是通过测试确定的,但是 IIRC 有人指出了源代码中的限制。
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?
嗯,理想情况下,是的,特别是如果您使用任何超出时间的约束。例如,如果您说您的工作需要网络连接,而设备失去连接,您的工作将停止。这可能会在 10 分钟的时间段结束之前发生。
Best practices?
尽可能避免周期性后台工作。
为了避免执行时间限制,我使用下面的练习解决了我的问题。
@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;
}
在为 Android Oreo 准备应用程序时,我阅读了 JobIntentService
over here.
在那里我发现(强调了重要部分):
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.
如果我看 documented limitations there is no word about any execution time limits. Also JobScheduler
does not mention anything.
- 这是我不应该关心的时间限制吗?
- 它没有记录吗?
- 或者执行时间限制 not/no 是否更长?
- 或者我是否必须以可以在任何给定时间点中断和重新启动的方式重新设计我的服务?最佳做法?
How long is the “JobService execution time limit” mentioned in Android's JobIntentService docs?
实际上好像是10分钟。我最初是通过测试确定的,但是 IIRC 有人指出了源代码中的限制。
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?
嗯,理想情况下,是的,特别是如果您使用任何超出时间的约束。例如,如果您说您的工作需要网络连接,而设备失去连接,您的工作将停止。这可能会在 10 分钟的时间段结束之前发生。
Best practices?
尽可能避免周期性后台工作。
为了避免执行时间限制,我使用下面的练习解决了我的问题。
@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;
}