Flutter workmanager: registration a new task with the same name

Issue

In the application I need to change a workmanager duration time for the same task.
I’m not sure is it required to cancel this task before?
For instance

Workmanager.registerPeriodicTask(
    "1",
    simplePeriodicTask,
    initialDelay: Duration(seconds: 10),
    frequency: Duration(minutes: minutes), //20 minutes
);

and after some time

Workmanager.registerPeriodicTask(
    "1",
    simplePeriodicTask,
    initialDelay: Duration(seconds: 10),
    frequency: Duration(minutes: minutes), //40 minutes
);

This is the same task. Do I need to cancel it before register a new one with the same name?

Solution

It’s clearly mentioned in the documentation

Existing Work Policy

Indicates the desired behaviour when the same task is scheduled more than once.
The default is KEEP

Workmanager.registerOneOffTask("1", "simpleTask", existingWorkPolicy: ExistingWorkPolicy.append);

Answered By – Ishanga Vidusha

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *