I am trying to implement pagination functionality in android. Each time activity starts I want to fetch new 10 records from collection.
Next time when I open the activity. lastVisible (DocumentSnapshot ) must be saved in SharedPreference to get the new list.
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);
}
How to save DocumentSnapshot(lastVisible) in SharedPreference ?
Or tell another approach to handle pagination..
Problem Solved following this approach