Tag: 进步

如何正确显示Google房间使用的异步任务的进度

我使用Google Room来实现Android应用程序(Kotlin代码)中的数据持久性。 房间要求所有的操作(来自和来自数据库的查询)是异步的。 我希望用户等待操作执行,防止他在查询结束之前与不能正确配置的组件进行交互。 我怎么能做到这一点,因为我不能从异步任务访问UI线程? PS:我也做了一些API调用进度/加载指标是很好的。 我在这些调用中使用RxJava,但是我对这项技术相当陌生,而且我不确定如何正确地构造它。 数据库操作示例: private fun getDataFromCache() { //show progress indicator here execute({ try { //Get items from cache val entities = daoData.findAll() if (entities.isNotEmpty()) { //do something } else { //do something else } } catch (e: Exception){ Log.e(“error”, e.toString()) } finally{ //dismiss progress indicator here } }) }