I'm using Android WorkManager version 1.0.0-beta-01
to upload some files to the server. Now I want to send back upload progress as it goes on (and not just the final result) to the caller.
class UploadWorker @Inject constructor(context: Application,
parameters: WorkerParameters,
private val uploadService: UploadService)
: RxWorker(context, parameters) {
@SuppressLint("CheckResult")
override fun createWork(): Single<Result> {
val filePath = inputData.getString(FILE_PATH)
//logic for sending files goes here where I want to send back the progress
return Single.just(Result.success())
}
}
I can achieve this by having a singleton object somewhere in my app with LiveData in it, then update the LiveData from my Work and listen to it in the caller but it doesn't seem like a good solution! Is there any better way to achieve this?