0

firebaseデータベースからすべての子ノードを取得できました。firebaseデータベースから更新された子データのみを取得する方法は?

enter image description here

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) { 

     } 
しかし、私の問題は、すべての新しいデータは、例えばノードの内側に追加したときに1件のより多くのデータが完全なデータその時 onDataChange()リターンでノード2 の内側に追加された場合ということです。私は更新されたデータだけを取得したい。

は今、私はこの応答を取得しています:

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 

答えて

0

あなたは子ノードが変更されているものを具体的に言った取得したい場合は、あなたがFirebaseのChildEventListenerを使用する必要があります。

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") 
    } 
    ... 

onChild* methodsは正確にあなたを教えて何が起こったの:onChildAddedonChildRemovedonChildChangedonChildMoved

Btw:少なくとも1年半前のFirebase SDKを使用していて、その後更新されていません。 I *は、Firebase SDKの新しいバージョンに切り替えることをお勧めします。既存のコードを変換する場合は、upgrade guideをご覧ください。

+0

実際には、新しいノードがサブチャイルドの下に追加されているかどうかを検出したいと思います。ノードが4または3の内側に追加されたとします。 –

+0

FirebaseデータベースSDKの 'onGrandchild *'イベントをリッスンする方法はありません。ユースケースに合わせてデータモデルを変更する必要があります。 –

+0

ありがとう、Frank ... 'addListenerForSingleValueEvent'を使用して複数のノードのデータを取得する方法はありますが、 –

関連する問題