I want to schedule 2 different periodic task, for this I am using work manager. 1. Upload file to server - after every 20 min 2. Call API in - after every 15 min
For API call (Daily operation) following is my code:
PeriodicWorkRequest.Builder dailyWorkBuilder =
new PeriodicWorkRequest.Builder(CheckAccount.class, 15,
TimeUnit.MINUTES)
.setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build());
PeriodicWorkRequest DailyJob = dailyWorkBuilder.build();
WorkManager.getInstance().enqueueUniquePeriodicWork("DailyJob", ExistingPeriodicWorkPolicy.REPLACE,DailyJob);
To upload file I am using following code:
PeriodicWorkRequest.Builder wifiWorkBuilder =
new PeriodicWorkRequest.Builder(FileUpload.class, 20,
TimeUnit.MINUTES)
.setConstraints(new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build());
PeriodicWorkRequest wifiWork = wifiWorkBuilder.build();
WorkManager.getInstance().enqueueUniquePeriodicWork("wifiJob", ExistingPeriodicWorkPolicy.REPLACE,wifiWork);
Now here I am facing 2 difficulties: 1. If I open app - Lets say after open app my Activity is HomeActivity in this activity I had written dailyWorkBuilder code (which executes after every 20 min) will get called every time I open app. If I did not open app it will get called after 20 min but before 20 min I open app it gets called. So here I want to check if task is not running then only it should execute not every time when I open app
- It also call wifiWorkBuilder (task which execute after every 15 min)it also get called every time when I open app. These 2 task are totally different and not depend on each other, but still if one task get called other will also get called before there specified time.
Whats wrong in above code. Any suggestion will be appreciated. Thanks