其他分享
首页 > 其他分享> > android – 为什么工作经理的工作人员仍然处于ENQUEUED状态?

android – 为什么工作经理的工作人员仍然处于ENQUEUED状态?

作者:互联网

我正在使用NetworkType.CONNECTED约束创建OneTimeWorkRequest,但即使设备连接到互联网,请求仍处于ENQUEUED状态

Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
            .setConstraints(constraints)
            .build();

WorkContinuation continuation = mWorkManager.beginUniqueWork("work",
                    ExistingWorkPolicy.KEEP, request);

continuation.enqueue();

解决方法:

试试这个?

Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
            .setConstraints(constraints)
            .build();

WorkManager.getInstance().enqueue(request);

标签:android,android-workmanager
来源: https://codeday.me/bug/20190710/1425324.html