保存 DocumentSnapshot 以在 Firestore android 中进行分页

2023-11-30

我正在尝试在android 中实现分页功能。每次活动开始时我想从集合中获取新的 10 条记录.

下次当我打开活动时。最后可见(文档快照)必须保存在 SharedPreference 中才能获取新列表。

        db = FirebaseFirestore.getInstance();

        //new code starts...
        Query first = null;

        if(new SharedPrefs(mContext).read("callForFristTime",true)){
            first = db.collection("questionCollection").whereEqualTo("questionType",1)
                    .orderBy("dateCreated")
                    .limit(numberOfQuestionFetched);

            new SharedPrefs(mContext).save("callForFristTime",false);
        }
        else{
            first = db.collection("questionCollection")
                    .whereEqualTo("questionType",1)
                    .orderBy("dateCreated")
                    .startAfter(lastVisible)//how could I save lastVisible
                    .limit(numberOfQuestionFetched);
        }

如何在 SharedPreference 中保存 DocumentSnapshot(lastVisible) ?

或者告诉另一种处理分页的方法..

问题解决了遵循这种方法


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

保存 DocumentSnapshot 以在 Firestore android 中进行分页 的相关文章

随机推荐