android - 在 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) ?
或者告诉另一种处理分页的方法..
按照这种方法解决的问题
解决方案
推荐阅读
- javascript - Javascript:代码重构为单行而不是多行 for 循环
- javascript - 不执行返回 - Javascript,React.js
- android - 如何更改列表数据结构firebase数据库android的值?
- android - 我想从谷歌登录中检索用户信息并将其放在导航侧边栏上
- gson - WELD-001408:具有限定符 @Default 的 Gson 类型的依赖关系不满足
- java - 我可以接受 JSONObject 作为 Rest API 中的参数吗?
- javascript - 广告插入器插件不显示来自服务器的广告
- java - Spring MVC 数据到 HTML5
- nlp - 使用谷歌翻译访问词级预测
- node.js - 在 ExpressJS 中处理可选参数的最佳实践