My question maybe a silly one, I´ve read the documentation but haven´t got a solution to my question. When I use limitToLast to get the last 15 messages (lets say from 5-20) and if I delete the 20th message, the childListener returns me messages like this (5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-4)... As you can see the last item is number 4.
The code is like so:messagesListener = FBMessagesRef.limitToLast(15).addChildEventListener(new ChildEventListener()
, how can I fix it and dont get the 4th item
The limitToLast() method is used to set a maximum number of children to be synced for a given callback. If we set a limit of 100, we will initially only receive up to 100 child_added events. If we have less than 100 messages stored in our database, a child_added event will fire for each message.
Querying DataWith Firebase database queries, you can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to be ordered using one of the ordering functions: orderByChild() , orderByKey() , or orderByValue() .
Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.
Since you're getting the last 15 digits when you set the value to 15, change the limitToLast
value to -1
to get the last Firebase value.
Change your code to below snippet.
messagesListener = FBMessagesRef.limitToLast(-1).addChildEventListener(new ChildEventListener(),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With