JobScheduler Periodic Job
When we create a Job we can set a lot of preperties and setPeriodic(interval) is a bit confusing for me. Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
- So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
- And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
I'm asking this becase I have tested it on a Job:
JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(JOB_ID, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(1000 * 60 * 15);
mJobScheduler.schedule(jobInfoBuilder.build());
And the job was not executed again in 30 mins ( I stopped waiting for it afterwards ) .
android
add a comment |
When we create a Job we can set a lot of preperties and setPeriodic(interval) is a bit confusing for me. Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
- So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
- And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
I'm asking this becase I have tested it on a Job:
JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(JOB_ID, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(1000 * 60 * 15);
mJobScheduler.schedule(jobInfoBuilder.build());
And the job was not executed again in 30 mins ( I stopped waiting for it afterwards ) .
android
add a comment |
When we create a Job we can set a lot of preperties and setPeriodic(interval) is a bit confusing for me. Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
- So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
- And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
I'm asking this becase I have tested it on a Job:
JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(JOB_ID, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(1000 * 60 * 15);
mJobScheduler.schedule(jobInfoBuilder.build());
And the job was not executed again in 30 mins ( I stopped waiting for it afterwards ) .
android
When we create a Job we can set a lot of preperties and setPeriodic(interval) is a bit confusing for me. Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
- So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
- And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
I'm asking this becase I have tested it on a Job:
JobInfo.Builder jobInfoBuilder = new JobInfo.Builder(JOB_ID, mServiceComponent)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setPeriodic(1000 * 60 * 15);
mJobScheduler.schedule(jobInfoBuilder.build());
And the job was not executed again in 30 mins ( I stopped waiting for it afterwards ) .
android
android
asked Nov 21 '18 at 15:03
Danil.BDanil.B
619
619
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
Yes, it ensures that this job executes only once within an interval of the specified width. The actual time of execution depends on the OS, subject to conditions like batching of jobs, in order to minimize the number of times the phone needs to wake from the idle state.
So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
The first time the job is called will be inside a 15 minute time window from the point when your code calls schedule
. After which since it is periodic, it will execute again within the next 15 minutes from the point when the last job finished, and so on. We have limited control over when in this interval the job will be executed, by setting the flexMillis
parameter in the other setPeriodic
method.
Let's say the first execution of your job is Job1. Once it finishes, it schedules the next job instance - Job2. Job2 now has 2 bounds - it can't run again before Job1's interval is up, and it must run before its own 15 minute interval finishes.
And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
The wantsReschedule
parameter is explained in the docs as follows:
boolean: true if this job should be rescheduled according to the back-off criteria specified when it was first scheduled; false otherwise.
The "job" here refers to a particular instance of your periodic job, not the original, periodic one. Let's say you are querying a server in order to show notifications on an hourly basis, and when the job was executed it couldn't fetch the data due to lack of internet. Your job may have finished execution, but it did not meet the requirement of updating data. If you set the parameter to true
, this instance of the periodic job will attempt to repeat itself according to the back-off policy (which should be exponential by default). Since it is considered the same instance, it does not violate the "will not recur more than once period" condition.
This means the OS will repeatedly try to schedule the job till it finished with the parameter as false
. This way, you don't have to wait one more hour for the next job, and may attempt again sooner. The next job according to the initial periodic settings will execute irrespective of this parameter being true
or false
.
That said, this repeated scheduling is battery intensive, and might result in many redundant calls. In most cases, the current job instance can be 'dropped' by setting the parameter to false
. The next scheduled job will still execute based on your initial parameters.
As for your code snippet, I'm not sure why it wasn't executed again. The code seems correct, just make sure you check throughout the period rather than exactly half an hour later. Also take into consideration special conditions like Doze mode, which will prevent almost all background service execution, and reschedule them later by itself.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414889%2fjobscheduler-periodic-job%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
Yes, it ensures that this job executes only once within an interval of the specified width. The actual time of execution depends on the OS, subject to conditions like batching of jobs, in order to minimize the number of times the phone needs to wake from the idle state.
So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
The first time the job is called will be inside a 15 minute time window from the point when your code calls schedule
. After which since it is periodic, it will execute again within the next 15 minutes from the point when the last job finished, and so on. We have limited control over when in this interval the job will be executed, by setting the flexMillis
parameter in the other setPeriodic
method.
Let's say the first execution of your job is Job1. Once it finishes, it schedules the next job instance - Job2. Job2 now has 2 bounds - it can't run again before Job1's interval is up, and it must run before its own 15 minute interval finishes.
And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
The wantsReschedule
parameter is explained in the docs as follows:
boolean: true if this job should be rescheduled according to the back-off criteria specified when it was first scheduled; false otherwise.
The "job" here refers to a particular instance of your periodic job, not the original, periodic one. Let's say you are querying a server in order to show notifications on an hourly basis, and when the job was executed it couldn't fetch the data due to lack of internet. Your job may have finished execution, but it did not meet the requirement of updating data. If you set the parameter to true
, this instance of the periodic job will attempt to repeat itself according to the back-off policy (which should be exponential by default). Since it is considered the same instance, it does not violate the "will not recur more than once period" condition.
This means the OS will repeatedly try to schedule the job till it finished with the parameter as false
. This way, you don't have to wait one more hour for the next job, and may attempt again sooner. The next job according to the initial periodic settings will execute irrespective of this parameter being true
or false
.
That said, this repeated scheduling is battery intensive, and might result in many redundant calls. In most cases, the current job instance can be 'dropped' by setting the parameter to false
. The next scheduled job will still execute based on your initial parameters.
As for your code snippet, I'm not sure why it wasn't executed again. The code seems correct, just make sure you check throughout the period rather than exactly half an hour later. Also take into consideration special conditions like Doze mode, which will prevent almost all background service execution, and reschedule them later by itself.
add a comment |
Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
Yes, it ensures that this job executes only once within an interval of the specified width. The actual time of execution depends on the OS, subject to conditions like batching of jobs, in order to minimize the number of times the phone needs to wake from the idle state.
So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
The first time the job is called will be inside a 15 minute time window from the point when your code calls schedule
. After which since it is periodic, it will execute again within the next 15 minutes from the point when the last job finished, and so on. We have limited control over when in this interval the job will be executed, by setting the flexMillis
parameter in the other setPeriodic
method.
Let's say the first execution of your job is Job1. Once it finishes, it schedules the next job instance - Job2. Job2 now has 2 bounds - it can't run again before Job1's interval is up, and it must run before its own 15 minute interval finishes.
And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
The wantsReschedule
parameter is explained in the docs as follows:
boolean: true if this job should be rescheduled according to the back-off criteria specified when it was first scheduled; false otherwise.
The "job" here refers to a particular instance of your periodic job, not the original, periodic one. Let's say you are querying a server in order to show notifications on an hourly basis, and when the job was executed it couldn't fetch the data due to lack of internet. Your job may have finished execution, but it did not meet the requirement of updating data. If you set the parameter to true
, this instance of the periodic job will attempt to repeat itself according to the back-off policy (which should be exponential by default). Since it is considered the same instance, it does not violate the "will not recur more than once period" condition.
This means the OS will repeatedly try to schedule the job till it finished with the parameter as false
. This way, you don't have to wait one more hour for the next job, and may attempt again sooner. The next job according to the initial periodic settings will execute irrespective of this parameter being true
or false
.
That said, this repeated scheduling is battery intensive, and might result in many redundant calls. In most cases, the current job instance can be 'dropped' by setting the parameter to false
. The next scheduled job will still execute based on your initial parameters.
As for your code snippet, I'm not sure why it wasn't executed again. The code seems correct, just make sure you check throughout the period rather than exactly half an hour later. Also take into consideration special conditions like Doze mode, which will prevent almost all background service execution, and reschedule them later by itself.
add a comment |
Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
Yes, it ensures that this job executes only once within an interval of the specified width. The actual time of execution depends on the OS, subject to conditions like batching of jobs, in order to minimize the number of times the phone needs to wake from the idle state.
So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
The first time the job is called will be inside a 15 minute time window from the point when your code calls schedule
. After which since it is periodic, it will execute again within the next 15 minutes from the point when the last job finished, and so on. We have limited control over when in this interval the job will be executed, by setting the flexMillis
parameter in the other setPeriodic
method.
Let's say the first execution of your job is Job1. Once it finishes, it schedules the next job instance - Job2. Job2 now has 2 bounds - it can't run again before Job1's interval is up, and it must run before its own 15 minute interval finishes.
And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
The wantsReschedule
parameter is explained in the docs as follows:
boolean: true if this job should be rescheduled according to the back-off criteria specified when it was first scheduled; false otherwise.
The "job" here refers to a particular instance of your periodic job, not the original, periodic one. Let's say you are querying a server in order to show notifications on an hourly basis, and when the job was executed it couldn't fetch the data due to lack of internet. Your job may have finished execution, but it did not meet the requirement of updating data. If you set the parameter to true
, this instance of the periodic job will attempt to repeat itself according to the back-off policy (which should be exponential by default). Since it is considered the same instance, it does not violate the "will not recur more than once period" condition.
This means the OS will repeatedly try to schedule the job till it finished with the parameter as false
. This way, you don't have to wait one more hour for the next job, and may attempt again sooner. The next job according to the initial periodic settings will execute irrespective of this parameter being true
or false
.
That said, this repeated scheduling is battery intensive, and might result in many redundant calls. In most cases, the current job instance can be 'dropped' by setting the parameter to false
. The next scheduled job will still execute based on your initial parameters.
As for your code snippet, I'm not sure why it wasn't executed again. The code seems correct, just make sure you check throughout the period rather than exactly half an hour later. Also take into consideration special conditions like Doze mode, which will prevent almost all background service execution, and reschedule them later by itself.
Documentation says that setPeriodic is used to "Specify that this job should recur with the provided interval not more than once per period".
Yes, it ensures that this job executes only once within an interval of the specified width. The actual time of execution depends on the OS, subject to conditions like batching of jobs, in order to minimize the number of times the phone needs to wake from the idle state.
So, I guess, if I set it to 15 mins it won't do Job every 15 mins(provided that I have not specified any other conditions for the job) - it's just ensures that the job is executed not more that once within interval I've set for Job, and it might take hour to start again?
The first time the job is called will be inside a 15 minute time window from the point when your code calls schedule
. After which since it is periodic, it will execute again within the next 15 minutes from the point when the last job finished, and so on. We have limited control over when in this interval the job will be executed, by setting the flexMillis
parameter in the other setPeriodic
method.
Let's say the first execution of your job is Job1. Once it finishes, it schedules the next job instance - Job2. Job2 now has 2 bounds - it can't run again before Job1's interval is up, and it must run before its own 15 minute interval finishes.
And JobService has a method jobFinished() which takes a boolean needsReschedule, if I set it to false will the Job still repeat itself in future if I set setPeriodic(1000 * 60 * 15) for it?
The wantsReschedule
parameter is explained in the docs as follows:
boolean: true if this job should be rescheduled according to the back-off criteria specified when it was first scheduled; false otherwise.
The "job" here refers to a particular instance of your periodic job, not the original, periodic one. Let's say you are querying a server in order to show notifications on an hourly basis, and when the job was executed it couldn't fetch the data due to lack of internet. Your job may have finished execution, but it did not meet the requirement of updating data. If you set the parameter to true
, this instance of the periodic job will attempt to repeat itself according to the back-off policy (which should be exponential by default). Since it is considered the same instance, it does not violate the "will not recur more than once period" condition.
This means the OS will repeatedly try to schedule the job till it finished with the parameter as false
. This way, you don't have to wait one more hour for the next job, and may attempt again sooner. The next job according to the initial periodic settings will execute irrespective of this parameter being true
or false
.
That said, this repeated scheduling is battery intensive, and might result in many redundant calls. In most cases, the current job instance can be 'dropped' by setting the parameter to false
. The next scheduled job will still execute based on your initial parameters.
As for your code snippet, I'm not sure why it wasn't executed again. The code seems correct, just make sure you check throughout the period rather than exactly half an hour later. Also take into consideration special conditions like Doze mode, which will prevent almost all background service execution, and reschedule them later by itself.
answered Nov 21 '18 at 15:49
TheGamer007TheGamer007
36927
36927
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414889%2fjobscheduler-periodic-job%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown