- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
因此来自 GcmNetworkManager 的 Android SDK
public static final int RESULT_RESCHEDULE
Indicates a task has failed to execute, and must be retried with back-off.
Task task = new OneoffTask.Builder()
.setService(MyService.class)
.setExecutionWindow(0, 15)
.setUpdateCurrent(true)
.setRequiredNetwork(Task.NETWORK_STATE_CONNECTED)
.setRequiresCharging(false)
.build();
mGcmNetworkManager.schedule(task);
在我的服务中
public int onRunTask(TaskParams taskParams) {
/** task execution logic here */
if (success) {
return RESULT_SUCCESS;
} else {
return RESULT_RESCHEDULE;
}
}
当执行失败时,会返回RESULT_RESCHEDULE,会重试。所以我想知道什么时候会重试?
谢谢
最佳答案
基于此documentation , RESULT_RESCHEDULE
意味着你的任务失败然后重新安排你的任务,所以它会在满足条件时再次执行。
By default, if you return
RESULT_RESCHEDULE
from youronRunTask
, your task is executed again as soon as conditions (charging, internet available) you defined for it are met.
- one option, if you need only to limit the count of reschedules is to store somewhere the number of reschedules, and when it reaches your defined limit, return
RESULT_FAILURE
instead ofRESULT_RESCHEDULE
- second one, if you need more control would be to return
RESULT_FAILURE
and schedule an OneOff task, make it recognizable by some special tag and again count how many times have you scheduled it somewhere, this way you will be able to control count and delay between executions of the task
但是,您可以检查这个 tutorial当您的代码经常失败并且必须重试时。 Java 7/8 库提供了丰富且不显眼的 API 以及针对此问题的快速且可扩展的解决方案。
希望这对您有所帮助!
关于android - 何时会再次执行 oneOffTaks 结果 GcmNetworkManager.RESULT_RESCHEDULE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42081143/
因此来自 GcmNetworkManager 的 Android SDK public static final int RESULT_RESCHEDULE Indicates a task has
我是一名优秀的程序员,十分优秀!