首页 > 解决方案 > 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)

标签: androidkotlingoogle-cloud-firestoreandroid-mvp

解决方案


推荐阅读