【发布时间】:2021-05-31 17:59:44
【问题描述】:
我有一个通过内容提供者从数据库中获取数据的流程。
fun getDataFlow(): Flow<Result> {
return flow {
emit(Result.Loading)
// fetchAll() is the method to fetch data via contentResolover.query()
val results = fetchAll()
emit(Result.Success(categories))
}.catch { e ->
emit(Result.Error(e))
}
}
那么如何在 ContentProvider 数据发生变化时触发重新获取数据(onChange 被调用)?
val contentObserver = object : ContentObserver(null) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
}
}
【问题讨论】:
标签: android android-contentprovider coroutine flow