为什么工作经理中的工人仍处于入队状态?

时间:2018-07-03 06:48:53

标签: android android-workmanager

我正在创建具有NetworkType.CONNECTED约束的OneTimeWorkRequest,但是即使设备已连接到Internet,请求仍处于“已排队”状态

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();

1 个答案:

答案 0 :(得分:0)

尝试一下?

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

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

WorkManager.getInstance().enqueue(request);