WorkManager OneTimeWorkRequest InitialDelay works after twise the time set










1















I'm facing problem with WorkManager OneTimeWorkRequest setInitialDelay.



It's work fine when app is in forground or in recent list. But When I remove App from recent list everything is messed up.



What I want to achieve ?
- I want send notification to user after few hours when some task is pending ,so after some R&D start work using WorkManager because of It's ability to Schedule Tasks without background service limitation.




Now below is code snippet which work till app is not removed from recent:




 Constraints constraints = new Constraints.Builder()
.setRequiresBatteryNotLow(true)
.build();

final OneTimeWorkRequest simpleRequest = new OneTimeWorkRequest.Builder(MyWorker.class)
.setInitialDelay(3, TimeUnit.MINUTES)
.setConstraints(constraints)
.addTag("simple_work")
.build();

WorkManager workManager = WorkManager.getInstance();

workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


Worker class



 public class MyWorker extends Worker 
private NotificationUtils notificationUtils;
public static final String EXTRA_OUTPUT_MESSAGE = "output_message";

public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams)
super(context, workerParams);


@NonNull
@Override
public Result doWork()

notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.showNotificationMessage("TITLE", "This is a MESSEAGE",2);

Data output = new Data.Builder()
.putString(EXTRA_OUTPUT_MESSAGE, "I have come from MyWorker!")
.build();

setOutputData(output);

return Result.SUCCESS;







Problem is After Remove It from recent list It's send notification but after double time which I set. for example I set setInitialDelay 5 minutes but It's work after 10 minutes.




So ,Please guide me what I do wrong or It's not for schedule task at specific time which I set for once. I don't want to keep repeat work after It's done. I'm create just new after finish first OneTimeWorkRequest so It has to work fine as per documented beginUniqueWork.




Library I am using : implementation "android.arch.work:work-runtime:1.0.0-alpha11"




English isn't my native language so pardon me for grammatically mistake:)










share|improve this question




























    1















    I'm facing problem with WorkManager OneTimeWorkRequest setInitialDelay.



    It's work fine when app is in forground or in recent list. But When I remove App from recent list everything is messed up.



    What I want to achieve ?
    - I want send notification to user after few hours when some task is pending ,so after some R&D start work using WorkManager because of It's ability to Schedule Tasks without background service limitation.




    Now below is code snippet which work till app is not removed from recent:




     Constraints constraints = new Constraints.Builder()
    .setRequiresBatteryNotLow(true)
    .build();

    final OneTimeWorkRequest simpleRequest = new OneTimeWorkRequest.Builder(MyWorker.class)
    .setInitialDelay(3, TimeUnit.MINUTES)
    .setConstraints(constraints)
    .addTag("simple_work")
    .build();

    WorkManager workManager = WorkManager.getInstance();

    workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


    Worker class



     public class MyWorker extends Worker 
    private NotificationUtils notificationUtils;
    public static final String EXTRA_OUTPUT_MESSAGE = "output_message";

    public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams)
    super(context, workerParams);


    @NonNull
    @Override
    public Result doWork()

    notificationUtils = new NotificationUtils(getApplicationContext());
    notificationUtils.showNotificationMessage("TITLE", "This is a MESSEAGE",2);

    Data output = new Data.Builder()
    .putString(EXTRA_OUTPUT_MESSAGE, "I have come from MyWorker!")
    .build();

    setOutputData(output);

    return Result.SUCCESS;







    Problem is After Remove It from recent list It's send notification but after double time which I set. for example I set setInitialDelay 5 minutes but It's work after 10 minutes.




    So ,Please guide me what I do wrong or It's not for schedule task at specific time which I set for once. I don't want to keep repeat work after It's done. I'm create just new after finish first OneTimeWorkRequest so It has to work fine as per documented beginUniqueWork.




    Library I am using : implementation "android.arch.work:work-runtime:1.0.0-alpha11"




    English isn't my native language so pardon me for grammatically mistake:)










    share|improve this question


























      1












      1








      1


      1






      I'm facing problem with WorkManager OneTimeWorkRequest setInitialDelay.



      It's work fine when app is in forground or in recent list. But When I remove App from recent list everything is messed up.



      What I want to achieve ?
      - I want send notification to user after few hours when some task is pending ,so after some R&D start work using WorkManager because of It's ability to Schedule Tasks without background service limitation.




      Now below is code snippet which work till app is not removed from recent:




       Constraints constraints = new Constraints.Builder()
      .setRequiresBatteryNotLow(true)
      .build();

      final OneTimeWorkRequest simpleRequest = new OneTimeWorkRequest.Builder(MyWorker.class)
      .setInitialDelay(3, TimeUnit.MINUTES)
      .setConstraints(constraints)
      .addTag("simple_work")
      .build();

      WorkManager workManager = WorkManager.getInstance();

      workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


      Worker class



       public class MyWorker extends Worker 
      private NotificationUtils notificationUtils;
      public static final String EXTRA_OUTPUT_MESSAGE = "output_message";

      public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams)
      super(context, workerParams);


      @NonNull
      @Override
      public Result doWork()

      notificationUtils = new NotificationUtils(getApplicationContext());
      notificationUtils.showNotificationMessage("TITLE", "This is a MESSEAGE",2);

      Data output = new Data.Builder()
      .putString(EXTRA_OUTPUT_MESSAGE, "I have come from MyWorker!")
      .build();

      setOutputData(output);

      return Result.SUCCESS;







      Problem is After Remove It from recent list It's send notification but after double time which I set. for example I set setInitialDelay 5 minutes but It's work after 10 minutes.




      So ,Please guide me what I do wrong or It's not for schedule task at specific time which I set for once. I don't want to keep repeat work after It's done. I'm create just new after finish first OneTimeWorkRequest so It has to work fine as per documented beginUniqueWork.




      Library I am using : implementation "android.arch.work:work-runtime:1.0.0-alpha11"




      English isn't my native language so pardon me for grammatically mistake:)










      share|improve this question
















      I'm facing problem with WorkManager OneTimeWorkRequest setInitialDelay.



      It's work fine when app is in forground or in recent list. But When I remove App from recent list everything is messed up.



      What I want to achieve ?
      - I want send notification to user after few hours when some task is pending ,so after some R&D start work using WorkManager because of It's ability to Schedule Tasks without background service limitation.




      Now below is code snippet which work till app is not removed from recent:




       Constraints constraints = new Constraints.Builder()
      .setRequiresBatteryNotLow(true)
      .build();

      final OneTimeWorkRequest simpleRequest = new OneTimeWorkRequest.Builder(MyWorker.class)
      .setInitialDelay(3, TimeUnit.MINUTES)
      .setConstraints(constraints)
      .addTag("simple_work")
      .build();

      WorkManager workManager = WorkManager.getInstance();

      workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


      Worker class



       public class MyWorker extends Worker 
      private NotificationUtils notificationUtils;
      public static final String EXTRA_OUTPUT_MESSAGE = "output_message";

      public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams)
      super(context, workerParams);


      @NonNull
      @Override
      public Result doWork()

      notificationUtils = new NotificationUtils(getApplicationContext());
      notificationUtils.showNotificationMessage("TITLE", "This is a MESSEAGE",2);

      Data output = new Data.Builder()
      .putString(EXTRA_OUTPUT_MESSAGE, "I have come from MyWorker!")
      .build();

      setOutputData(output);

      return Result.SUCCESS;







      Problem is After Remove It from recent list It's send notification but after double time which I set. for example I set setInitialDelay 5 minutes but It's work after 10 minutes.




      So ,Please guide me what I do wrong or It's not for schedule task at specific time which I set for once. I don't want to keep repeat work after It's done. I'm create just new after finish first OneTimeWorkRequest so It has to work fine as per documented beginUniqueWork.




      Library I am using : implementation "android.arch.work:work-runtime:1.0.0-alpha11"




      English isn't my native language so pardon me for grammatically mistake:)







      java android android-jetpack android-workmanager






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 6:14







      b devloper

















      asked Nov 14 '18 at 13:56









      b devloperb devloper

      185317




      185317






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You problem is not clear though please update latest work manager lib to android.arch.work:work-runtime:1.0.0-beta03



          And you can explain me why do u need to enque the unique work ?



          workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


          try to replace it with workManager.enque(simpleRequest); and let me know if worked






          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%2f53301908%2fworkmanager-onetimeworkrequest-initialdelay-works-after-twise-the-time-set%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









            0














            You problem is not clear though please update latest work manager lib to android.arch.work:work-runtime:1.0.0-beta03



            And you can explain me why do u need to enque the unique work ?



            workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


            try to replace it with workManager.enque(simpleRequest); and let me know if worked






            share|improve this answer



























              0














              You problem is not clear though please update latest work manager lib to android.arch.work:work-runtime:1.0.0-beta03



              And you can explain me why do u need to enque the unique work ?



              workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


              try to replace it with workManager.enque(simpleRequest); and let me know if worked






              share|improve this answer

























                0












                0








                0







                You problem is not clear though please update latest work manager lib to android.arch.work:work-runtime:1.0.0-beta03



                And you can explain me why do u need to enque the unique work ?



                workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


                try to replace it with workManager.enque(simpleRequest); and let me know if worked






                share|improve this answer













                You problem is not clear though please update latest work manager lib to android.arch.work:work-runtime:1.0.0-beta03



                And you can explain me why do u need to enque the unique work ?



                workManager.beginUniqueWork("simple_work", ExistingWorkPolicy.KEEP, simpleRequest).enqueue();


                try to replace it with workManager.enque(simpleRequest); and let me know if worked







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 11 at 14:06









                anshulanshul

                375528




                375528





























                    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%2f53301908%2fworkmanager-onetimeworkrequest-initialdelay-works-after-twise-the-time-set%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







                    這個網誌中的熱門文章

                    How to read a connectionString WITH PROVIDER in .NET Core?

                    Node.js Script on GitHub Pages or Amazon S3

                    Museum of Modern and Contemporary Art of Trento and Rovereto