admin管理员组

文章数量:1122832

// Create WorkRequest for TaskSchedulerWorker (Worker A)
OneTimeWorkRequest workRequestA = new OneTimeWorkRequest.Builder(SchedulerWorker.class)
        .addTag(TraiQosAppConstants.SchedulerWorker_Tag)
        .setInputData(inputData)
        .build();

// Create WorkRequest for ReServiceWorker (Worker B)
OneTimeWorkRequest workRequestB = new OneTimeWorkRequest.Builder(ReServiceWorker.class)
        .addTag(TraiQosAppConstants.ReServiceWorker_Tag)
        .build();

// Chain Worker A and Worker B
WorkManager.getInstance(context)
        .beginWith(workRequestA)
        .then(workRequestB) // WorkRequest B only executes if WorkRequest A is successful
        .enqueue();

The issue is that the app crashes when it tries to execute the second WorkRequest (Worker B). The log shows the following error before the crash:

Setting status to enqueued for 59d83914-fb1f-4f22-804d-e091561fd032 2024-11-20 17:00:19.558 19153-19153 AndroidRuntime
com.package name D Shutting down VM

I've ensured that both workers are correctly implemented and return Result.success() upon successful completion. However, the app still crashes after Worker A finishes, and Worker B is supposed to start.

本文标签: androidWorkManager Chaining Crashes After Executing First WorkRequestStack Overflow