WorkManager Observer not receiving result

Viewed 44

I have a function with a worker that checks for internet when opening the app the function works ok so far. Now that I'm upgrading the app for TIRAMISU, the Observable in the Worker is not triggering. In the logcat I can see the message:

I/WM-WorkerWrapper: Worker result SUCCESS for Work...

But the result is not delivered to the Observer in the getWorkInfoByIdLiveData. This is the function that dispatches the Worker:

private void isInternetAvailable() {
        OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(InternetCheck.class).build();
        WorkManager workManager = WorkManager.getInstance(ActivitySplash.this);
        workManager.enqueue(workRequest);
        workManager.getWorkInfoByIdLiveData(workRequest.getId())
                .observe(ActivitySplash.this, workInfo -> {
                    if (!workInfo.getState().isFinished())
                        return;
                    if (workInfo.getState() == WorkInfo.State.SUCCEEDED) {
                        requestAdsConsent();
                    } else {
                        consentStatus = ConsentStatus.PERSONALIZED;
                        startActivity();
                    }
                });
    }

Quite simple and has been working fine until now, I guess I must have missed anything new regarding the WorkManager configuration in the latest releases. I have checked that the Id of the worker is the same as the one in the logcat on SUCCESS. Either if the Worker FAILS or SUCCEED the Observer is not being triggered, the result is not getting to the Observer.

Any ideas what am I missing here? I have the Latest version of WorkManager with compileSdkVersion 33

implementation 'androidx.work:work-runtime:2.7.1'

EDIT: I have made sure that the app has not changed its Lifecycle State, it is RESUMED.

0 Answers
Related