android - android kotlin firestore 在放置在非活动类中时返回 0 值
问题描述
将我的 Firestore 快照侦听器放在非活动类中是否有问题?
我试图在我的模型(MVP)中添加快照侦听器,但它返回 0,
但是当我在活动类中访问它时,它返回值。
这是我的代码:
override fun fetchJsonToFirestore(activity: Activity) {
FirebaseFirestore
.getInstance()
.collection("devices")
.addSnapshotListener(activity)
{ querySnapshot: QuerySnapshot?, e: FirebaseFirestoreException? ->
for (document in querySnapshot!!.documents) {
if (document.exists()) {
val notifPojo = document.toObject(Device::class.java!!)
mobileList.add(notifPojo!!)
}
}
}
presenter.mobileList(mobileList)
解决方案
推荐阅读
- python - 使用python在excel中创建和保存数据新表
- video - 使用 VLC 将视频流从相机写入文件
- php - processDatamap_beforeStart Hook - 获取 TYPO3 中的实际 UID
- python - 包含 for 循环的 Python 函数仅返回最后一个结果
- html - 页面链接在域的角度构建中不起作用
- html - HTML/CSS 表格单元在底部仅对齐一个按钮;
- html - css - 如何保持元素与较小显示器的关系
- php - Laravel 干预无法从给定的 WEBP 类型文件的二进制数据初始化
- python - 如何从python字典中提取相应的值?
- python - 是否可以为 RGB 和灰度图像创建训练矩阵