Fixed
Status Update
Comments
ru...@gmail.com <ru...@gmail.com> #2
Seems like it happens on API 21-22 too.
su...@google.com <su...@google.com> #3
This is expected. You are calling: enqueueUniquePeriodicWork() with an ExistingPeriodicWorkPolicy.REPLACE. This will cancel running work, and kick off new instances of all Workers.
https://github.com/rubensousa/WorkManagerKitkatBug/blob/master/app/src/main/java/com/github/rubensousa/workkitkatbug/MainActivity.kt#L24
ru...@gmail.com <ru...@gmail.com> #4
I just ran the sample again and now the behaviour is different for some weird reason. I forgot to mention that I only used REPLACE to test this properly. Because it also happens with KEEP.
ra...@google.com <ra...@google.com> #5
And shouldn't the behaviour be consistent across all Android versions?
ra...@google.com <ra...@google.com> #6
We don't see any issues with KEEP. If you have a way for us to reproduce any problems, please send us the appropriate instructions.
to...@gmail.com <to...@gmail.com> #7
Ok, I found something odd. Seems like setRequiredNetworkType(NetworkType.UNMETERED) causes this for some reason. I'm going to update the sample so you can review this again. Please, reopen this since it's not intended behavior.
ru...@gmail.com <ru...@gmail.com> #8
This happens on a fresh install with KEEP instead of REPLACE if the constraints have setRequiredNetworkType(NetworkType.UNMETERED). I've updated the sample
ru...@gmail.com <ru...@gmail.com> #9
"And shouldn't the behaviour be consistent across all Android versions?"
The behavior is actually consistent. Once your worker starts running, if we get a call to enqueueUniquePeriodicWork a new work request and with ExistingPeriodicWorkPolicy.REPLACE we will stop existing work.
If your Worker was not running, then there is nothing to cancel. This is just a matter of timing.
The behavior is actually consistent. Once your worker starts running, if we get a call to enqueueUniquePeriodicWork a new work request and with ExistingPeriodicWorkPolicy.REPLACE we will stop existing work.
If your Worker was not running, then there is nothing to cancel. This is just a matter of timing.
ed...@gmail.com <ed...@gmail.com> #10
I'm not arguing against the expected behavior of ExistingPeriodicWorkPolicy.REPLACE, since that's working as intended. But this is happening only when setRequiredNetworkType(NetworkType.UNMETERED) is used while having ExistingPeriodicWorkPolicy.KEEP.
da...@gmail.com <da...@gmail.com> #11
Can you send us an updated sample ?
Description
Version used: implementation 'android.arch.work:work-runtime:1.0.0-alpha12'
Devices/Android versions reproduced on: Moto e3 Power / Andorid 6.0 Marshmallow
Sometimes Periodic workManager gets called two times.
This is my built.gradle file:-
compileSdkVersion 28
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Here is this code:-
//---------------------------------------------------------Class Login---------------------------------------------------------------------------------------//
SaveData("Frist");
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(DailyLogoutTask.class,
1, TimeUnit.DAYS)
.build();
WorkManager.getInstance().enqueueUniquePeriodicWork("DailyTaskRestaurantLite"
, ExistingPeriodicWorkPolicy.KEEP
, periodicWorkRequest);
private void SaveData(String str) {
SharedPreferences.Editor preferencesEditor = mPreferences.edit();
preferencesEditor.putString("Status1", str);
preferencesEditor.apply();
}
//------------------------------------------------------Class DailyLogoutTask-----------------------------------------------------------------------//
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import android.util.Log;
import com.domo.ClsGlobal;
import com.demo.classes.ClsUserInfo;
import androidx.work.Result;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import static android.content.Context.MODE_PRIVATE;
public class DailyLogoutTask extends Worker {
private SharedPreferences mPreferences;
private static final String mPreferncesName = "MyPerfernces";
Context context;
public DailyLogoutTask(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
this.context = context;
mPreferences = context.getSharedPreferences(mPreferncesName, MODE_PRIVATE);
Log.e("DailyLogoutTask", "DailyLogoutTask call");
}
@NonNull
@Override
public Result doWork() {
String getstatus = mPreferences.getString("Status1", "No Task Perform");
Log.d("---getstatus---", "----getstatus---" + getstatus);
Log.e("doWork", "doWork call");
if (!getstatus.equalsIgnoreCase("Frist")) {
ClsUserInfo userInfo = new ClsUserInfo();
ClsUserInfo userLoginStatus = ClsGlobal.getUserInfo(context);
if (!userLoginStatus.getLoginStatus().equalsIgnoreCase("DEACTIVE")){
Log.e("chack", "Logout");
userInfo.setLoginStatus("DEACTIVE");
ClsGlobal.setUserInfo(userInfo, context);
// ClsGlobal.sendNotification("IF", "IF background Logout".concat(ClsGlobal.getEntryDate()),context);
WorkManager.getInstance().cancelUniqueWork("DailyTaskRestaurantLite");
Log.d("getFirstDateOfMonth", "----UserInfo---" + userLoginStatus.getLoginStatus());
}
} else {
Log.e("chack", "Not Frist");
// ClsGlobal.sendNotification("ELSE", "ELSE background Logout".concat(ClsGlobal.getEntryDate()),context);
SaveData("Second");
}
return Result.success();
}
private void SaveData(String str) {
Log.e("SaveData", str);
SharedPreferences.Editor preferencesEditor = mPreferences.edit();
preferencesEditor.putString("Status1", str);
preferencesEditor.apply();
}
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).