0

Je suis capable d'extraire le nœud enfant de la base de données Firebase.Comment obtenir uniquement les données enfant mises à jour à partir de la base de données Firebase?

Firebase firebase = new Firebase("https://myfiebase-url.firebaseio.com/"); 
    firebase.addValueEventListener(new com.firebase.client.ValueEventListener() { 
     @Override 
     public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) { 
      System.out.println(dataSnapshot.getValue()); 
      Log.e("testing message", dataSnapshot.getValue() + "--->") 
      } 


     @Override 
     public void onCancelled(FirebaseError firebaseError) { 

     } 

enter image description here

Mais mon problème est que lorsque de nouvelles données à l'intérieur ajouter nœud par exemple si l'on est plus de données ajouté à l'intérieur noeud 2. A ce moment-là onDataChange() retour les données complètes. Je veux récupérer uniquement les données mises à jour.

Maintenant, je reçois cette réponse:

E/testing message: [null, {-KrBu6CM_IP7xwQHcYOT={date=10-08-2017, stared=, chatId=, time=Thu Aug 10 21:39:32 GMT+05:30 2017, message=Gagsgs, userId=0, timeStamp=}, -KrXiYBOUqeZ7BtzF9jw={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 03:20:38 IST 2017, message=Fggffg, userId=0, timeStamp=}, -KquvlHuja1PZ-hoW-Xf={date=07-08-2017, stared=, chatId=, time=Mon Aug 07 09:53:35 GMT+05:30 2017, message=Xvxcggg, userId=0, timeStamp=}, -KrXb8scQ3blRzt3HzUX={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:48:20 GMT+05:30 2017, message=Tggggg, userId=0, timeStamp=}, -KrXatbjGvt8HlZetAHN={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:47:13 GMT+05:30 2017, message=Gggfy, userId=0, timeStamp=}, -KrXaZINL9_ZEAMbVE_1={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:45:46 GMT+05:30 2017, message=Shubhank, userId=0, timeStamp=}, -KrXbBgEhJA3CMlHlTtX={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:48:31 GMT+05:30 2017, message=Tyyggg, userId=0, timeStamp=}, -KrXfVrqlVw8OXPOzjlw={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 03:07:22 GMT+05:30 2017, message=Fggh, userId=0, timeStamp=}, -KrXaV5zkbz369g4n2_N={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:45:28 GMT+05:30 2017, message=Gghhu, userId=0, timeStamp=}, -KrXb2rZgm98Jiu8dZ7I={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:47:55 GMT+05:30 2017, message=Ytttt, userId=0, timeStamp=}, -KrXb1Mkp1pir5PekCGp={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:47:49 GMT+05:30 2017, message=Ttttt, userId=0, timeStamp=}, -KrXacX7z-InOYNLa6zB={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:46:03 GMT+05:30 2017, message=Eeqdss, userId=0, timeStamp=}, -KrXagbxXVN5dx1YkPBD={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:46:20 GMT+05:30 2017, message=Mn mm, userId=0, timeStamp=}, -KrXcbNyUQo8ia7WRoO1={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:54:43 IST 2017, message=Bdhdhdd, userId=0, timeStamp=}, -KrXcZLhA5RVJceDPai6={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:54:30 IST 2017, message=Xdff, userId=0, timeStamp=}, -KrXagsuQ2iLmJVhbnoi={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:46:21 GMT+05:30 2017, message=Lp, userId=0, timeStamp=}, -KrXhz1XeWxYguDNt8Yv={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 03:18:10 GMT+05:30 2017, message=Fhfdt, userId=0, timeStamp=}, -KrXanJdSh9iPqCJCUT0={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:46:47 GMT+05:30 2017, message=Ghjhh, userId=0, timeStamp=}, -KrXb-jZqlwOEbUswppw={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:47:42 GMT+05:30 2017, message=Dfgffg, userId=0, timeStamp=}, -KrXeHxow-Jb5n0LuW5s={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 03:02:03 IST 2017, message=Ftffft, userId=0, timeStamp=}, -KrXcV2Og5InEEtDacMj={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:54:13 IST 2017, message=Gfggg, userId=0, timeStamp=}, -KrXb6zFyP5DnaexkMmU={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:48:12 GMT+05:30 2017, message=Tttt, userId=0, timeStamp=}, -KrXc4bhHWZsQfbVj8HU={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:52:25 IST 2017, message=Vhhhh, userId=0, timeStamp=}, -KquvqzMKh3eNEnIzhhr={date=07-08-2017, stared=, chatId=, time=Mon Aug 07 09:53:59 GMT+05:30 2017, message=Gdgsggdd, userId=0, timeStamp=}, -KrXayJVxlC3hXqSiVnF={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:47:32 GMT+05:30 2017, message=Frsddr, userId=0, timeStamp=}, -KqqdBq5Ui8Ij-jg5kN2={date=06-08-2017, stared=, chatId=, time=Sun Aug 06 13:53:59 GMT+05:30 2017, message=Gfggg, userId=0, timeStamp=}}, {-KrXSl1kSbbQF38mHXtb={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:07:18 GMT+05:30 2017, message=Gggg, userId=0, timeStamp=}, -KrX6yitdWGiBF4SR2MJ={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 00:32:08 GMT+05:30 2017, message=Gggg, userId=0, timeStamp=}, -KrXTEKQpj1Sz7qUkgRp={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 02:09:23 GMT+05:30 2017, message=Cffg, userId=0, timeStamp=}}, {-KrXLO1INF4-0HewRVD7={date=15-08-2017, stared=, chatId=, time=Tue Aug 15 01:35:05 GMT+05:30 2017, message=Aastha, userId=0, timeS 

Répondre

0

Si vous voulez vous dire ce nœud enfant spécifique a été modifié, vous devez utiliser ChildEventListener de Firebase:

firebase.addChildEventListener(new com.firebase.client.ChildEventListener() { 
    @Override 
    public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String previousChildKey) { 
     Log.i("onChildAdded", "Child "+dataSnapshot.getKey()+" was added after "+previousChildKey) 
    } 

    @Override 
    public void onChildRemoved(com.firebase.client.DataSnapshot dataSnapshot) { 
     Log.i("onChildRemoved", "Child "+dataSnapshot.getKey()+" was removed") 
    } 
    ... 

Le onChild* methods vous dire exactement ce qui s'est passé: onChildAdded, onChildRemoved, onChildChanged et onChildMoved. Btw: vous utilisez un SDK Firebase datant d'au moins un an et demi et qui n'a pas été mis à jour depuis. I fortement * vous recommandons de passer à une nouvelle version de Firebase SDK. Si vous cherchez à convertir du code existant, regardez le upgrade guide.

+0

mais en fait je veux détecter si le nouveau noeud est ajouté sous sous-enfant. Supposons que le nœud soit ajouté à l'intérieur de 4 ou 3. –

+0

Il n'y a aucun moyen d'écouter les événements 'onGrandchild *' dans le SDK Database Firebase. Vous devrez changer votre modèle de données pour accommoder votre cas d'utilisation. –

+0

Merci, Frank ... il y a un moyen d'extraire des données de plusieurs nœuds en utilisant 'addListenerForSingleValueEvent' –