首页 > 解决方案 > 在 Firestore android 中保存 DocumentSnapshot 以进行分页

问题描述

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

下次我打开活动时。lastVisible (DocumentSnapshot)必须保存在 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) ?

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

按照这种方法解决的问题

标签: androidpaginationgoogle-cloud-firestore

解决方案


推荐阅读