WorkManager OneTimeWorkRequest InitialDelay works after twise the time set
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
add a comment |
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
add a comment |
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
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
java android android-jetpack android-workmanager
edited Nov 21 '18 at 6:14
b devloper
asked Nov 14 '18 at 13:56
b devloperb devloper
185317
185317
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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%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
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
add a comment |
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
add a comment |
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
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
answered Feb 11 at 14:06
anshulanshul
375528
375528
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%2f53301908%2fworkmanager-onetimeworkrequest-initialdelay-works-after-twise-the-time-set%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