Scheduled job executes multiple time in Evernote- AndroidJob

后端 未结 2 1992
花落未央
花落未央 2021-02-15 16:14

I have one periodic job I want to run and it is implemented with the help of Evernote\'s Android Job library.

What I wish to achieve is to updateMyLocation ever 15 mins.

2条回答
  •  广开言路
    2021-02-15 17:11

    In case of WorkManager, I have added .beginUniqueWork() before .enqueue() and it worked for me.

      Constraints myConstraints = new Constraints.Builder()
                    .setRequiredNetworkType(NetworkType.CONNECTED)
                    .build();
      Data.Builder basicWorkerInputDataBuilder = new Data.Builder();
    
      OneTimeWorkRequest otwRequest = new OneTimeWorkRequest.Builder(BasicOneTimeWorker.class)                  
                    .setConstraints(myConstraints).addTag("BasicOneTimeWorker")                    
                    .setInputData(basicWorkerInputDataBuilder.build());
    
      WorkManager.getInstance().beginUniqueWork("uniqueBasicOneTimeWork",
                                                ExistingWorkPolicy.REPLACE,
                                               otwRequest).enqueue();
    

    The below discussion helped me to find the solution.

    https://github.com/googlecodelabs/android-workmanager/issues/16

    https://issuetracker.google.com/issues/111569265

提交回复
热议问题