I am extending the Worker
class and in its doWork()
method I'm uploading files to the cloud. The app uploads files when it is in foreground, but If I kill the app the doWork
process stops. After opening the app again, it starts to run and completes the task. This means it was not running in the background. I want to run a worker thread even if app is not in the foreground. Should I add something into the manifest file or any flag to the Activity
. Any help will be appreciated.
The dowork()
method can be called from the uploadworker
instance.
OneTimeWorkRequest uploadworker = new OneTimeWorkRequest.Builder(VideoUploadWorker.class)
.build();
WorkManager.getInstance().enqueue(uploadworker);
This code is working perfectly when app is in foreground. I tested in many devices but I got same results.