Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 获取Firestore Android的最新数据_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 获取Firestore Android的最新数据

Java 获取Firestore Android的最新数据,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我正在Android上开发一款社交网络类型的应用程序。我的项目已连接到Firebase。一切都很完美。但是我需要它,例如,出版物从最新的到最旧的返回。我正在使用CloudFireStore FirebaseFirestore db = FirebaseFirestore.getInstance(); CollectionReference collectionReference = db.collection("eventos"); collectionReference.limit(2).g

我正在Android上开发一款社交网络类型的应用程序。我的项目已连接到Firebase。一切都很完美。但是我需要它,例如,出版物从最新的到最旧的返回。我正在使用CloudFireStore

FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference collectionReference = db.collection("eventos");

collectionReference.limit(2).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
    @Override
    public void onSuccess(QuerySnapshot documentSnapshots) {
        datos.removeAll(datos);

        for (DocumentSnapshot document : documentSnapshots.getDocuments()) {
            Map<String, Object> mapaEvento = document.getData();
            vento evento = new Evento((String) mapaEvento.get("usuario"), (String) mapaEvento.get("titulo"), (String) mapaEvento.get("categoria"));
            datos.add(evento);
         }
         adaptadorRecyclerHome.notifyDataSetChanged();
    }
});
FirebaseFirestore db=FirebaseFirestore.getInstance();
CollectionReference CollectionReference=db.collection(“eventos”);
collectionReference.limit(2.get().addOnSuccessListener(新OnSuccessListener()){
@凌驾
成功时公共无效(QuerySnapshot文档快照){
datos.removeAll(datos);
对于(DocumentSnapshot文档:documentSnapshots.getDocuments()){
Map mapaEvento=document.getData();
vento evento=new evento((String)mapaEvento.get(“usuario”),(String)mapaEvento.get(“titulo”),(String)mapaEvento.get(“categia”);
datos.add(evento);
}
AdapterHome.notifyDataSetChanged();
}
});
我该怎么做

JSON
插入firebase时,添加另一个名为
timestamp
的字段,该字段具有插入时间

然后使用to
orderByChild('timestamp')


如果你不明白,我想要的是从最新到最旧的数据。这似乎是最佳的解决方案。
 Query query = db.child("eventos").orderByChild("timestamp");