I am trying to make an API call from the doWork()
method of WorkManager. I receive MutableLiveData
with a list from the response. How do I set this complex object as an output from WorkManager?
Please find below the implementation for the same:
class FetchWorkManager(context: Context, params: WorkerParameters): Worker(context, params) {
var postInfoLiveData: LiveData<List<PostInfo>> = MutableLiveData()
@SuppressLint("RestrictedApi")
override fun doWork(): Result {
fetchInfoFromRepository()
// Setting output data
val data = Data.Builder()
.putAll(postInfoLiveData)
//.put("liveData", postInfoLiveData)
.build()
return Result.success(data)
}
fun fetchInfoFromRepository() {
val retrofitRepository = RetrofitRepository()
postInfoLiveData = retrofitRepository.fetchPostInfoList()
}
}
Can anyone help me in resolving this issue?
Room Database
even if your app is running out from background – Sight