Flow

作者: lixinxin | 来源:发表于2022-06-25 16:33 被阅读0次

fun insert(categoryName: String) {
viewModelScope.launch {
val category =
CategoryData(0,
categoryName,
System.currentTimeMillis(),
System.currentTimeMillis())
AppDatabase.getCategoryDao(getApplication()).insert(category)
Log.d("CategoryViewModel", "insert :$category")
}
}

fun getAll(): Flow<List<CategoryData>> {
    return AppDatabase.getCategoryDao(getApplication())
        .getAll()
        .catch { e -> e.printStackTrace() }
        .flowOn(Dispatchers.IO)
}

相关文章

网友评论

      本文标题:Flow

      本文链接:https://www.haomeiwen.com/subject/rxiivrtx.html