我正在尝试安排应用程序在1分钟后启动的时间,我需要做一些工作,不管应用程序是否仍在前台,但是我需要这样做,但是我不知道为什么我的doWork方法无法运行。但是onStart方法称为多次
private void sacduleThePaddingNotifaction() {
OneTimeWorkRequest postNotationWithDelay =
new OneTimeWorkRequest.Builder(PostNotificationWork.class)
.setInitialDelay(1,TimeUnit.MINUTES)
.build();
WorkManager.getInstance().enqueue(postNotationWithDelay);
}
我的工人阶级
public class PostNotificationWork extends Worker {
@Override
public void onStartWork(@NonNull WorkFinishedCallback callback) {
Log.d("PostNotificationWork: ","onStartWork");//this called many times, some time 4 time
}
@NonNull
@Override
public Result doWork() {
Log.d("PostNotificationWork: ","Posting notification");
return Result.SUCCESS;
}
}
我正在使用def work_version = "1.0.0-alpha07"
答案 0 :(得分:0)
def work_version = "1.0.0-alpha06"
implementation "android.arch.work:work-runtime:$work_version"
@Override
public void onStartWork(@NonNull WorkFinishedCallback callback) {
Log.d("PostNotificationWork: ","onStartWork");//this called many times, some time 4 time
}
答案 1 :(得分:0)
请不要覆盖onStartWork()
。即使您需要拨打super.onStartWork()
。我们仍在研究NonBlockingWorker
API的人体工程学。