Firebase Firestore get data from collection

后端 未结 6 966
悲&欢浪女
悲&欢浪女 2020-11-29 09:19

I want to get data from my Firebase Firestore database. I have a collection called user and every user has collection of some objects of the same type (My Java custom object

6条回答
  •  野性不改
    2020-11-29 10:11

    Try this..Working fine.Below function will get Realtime Updates from firebse as well..

    db = FirebaseFirestore.getInstance();
    
    
            db.collection("dynamic_menu").addSnapshotListener(new EventListener() {
                @Override
                public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
    
                    if (e !=null)
                    {
    
                    }
    
                    for (DocumentChange documentChange : documentSnapshots.getDocumentChanges())
                    {
                     String   isAttendance =  documentChange.getDocument().getData().get("Attendance").toString();
                     String  isCalender   =  documentChange.getDocument().getData().get("Calender").toString();
                     String isEnablelocation = documentChange.getDocument().getData().get("Enable Location").toString();
    
                       }
                    }
            });
    

    More reference :https://firebase.google.com/docs/firestore/query-data/listen

    If You do not want realtime updates refer Below Document

    https://firebase.google.com/docs/firestore/query-data/get-data

提交回复
热议问题