我用的是Android WorkManager
version 1.0.0-beta-01
上传一些文件到服务器。现在我想把上传进度(不仅仅是最终结果)发送给调用者。
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())
}
}
我可以通过在我的应用程序中的某个地方使用一个带有LiveData的singleton对象来实现这一点,然后从我的工作中更新LiveData并在调用者中监听它,但这似乎不是一个好的解决方案!
有没有更好的方法来实现这个目标?