JobScheduler Periodic Job












0















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 ) .










share|improve this question



























    0















    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 ) .










    share|improve this question

























      0












      0








      0








      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 ) .










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 15:03









      Danil.BDanil.B

      619




      619
























          1 Answer
          1






          active

          oldest

          votes


















          1















          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.






          share|improve this answer























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1















            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.






            share|improve this answer




























              1















              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.






              share|improve this answer


























                1












                1








                1








                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.






                share|improve this answer














                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 15:49









                TheGamer007TheGamer007

                36927




                36927






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin