I'm trying to make a worker-run every 15 minutes using the new WorkManager API, 1.0.0-alpha06.
If I'm not wrong, using Work manager with PeriodicWorkRequest
should make the worker outlive task kills and phone reboots, but when I swipe the task from the Recent Apps the scheduled worker is lost (I've waited for around 45 minutes to see any logs of the worker scheduled for 15 minutes interval).
these are my files:
MyExampleWorker.java:
public class MyExampleWorker extends Worker{
public static final String TAG = "MY_EXAMPLE_WORKER";
@NonNull
@Override
public Result doWork() {
Log.i(TAG, "Starting background worker");
// Getting configuration data
long param1 = getInputData().getLong("param1", 60000);
String param2 = getInputData().getString("param2");
String param3 = getInputData().getString("param3");
PackageManager pckMgr = mContext.getPackageManager();
...
..
.
return Result.SUCCESS;
}
}
Main.java: this method fires as soon as the app is launched
@ReactMethod
public void execute() {
Log.i(TAG, "inside execute, setting up periodic worker in workManager");
Data inputData = new Data.Builder()
.putLong("param1", 60000)
.putString("param2", "something")
.putString("param3", "something else")
.build();
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest
.Builder(MyExampleWorker.class, PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS, TimeUnit.MILLISECONDS)
.setInputData(inputData)
.addTag(MyExampleWorker.TAG)
.build();
WorkManager.getInstance().enqueueUniquePeriodicWork(MyExampleWorker.TAG, ExistingPeriodicWorkPolicy.KEEP, periodicWorkRequest);
}
UPDATE: Not only that, but if I open the app once again I see the log for "inside execute, setting up a periodic worker in workManager" but seems the worker is not scheduled, it has been over an hour and no logs for the worker are present in logcat.
Am I missing something here?
Any help is GREATLY appreciated!!
Diego