Check the last three data stored in Firebase with Android

0

Good morning, I am making a query to the last three data saved to be compared

si el ultimo es menor que el segundo y primer dato guardado entonces realizar accion.

I have the data saved as follows

the data in red are the doses that I should call the last 3. Does anyone know how I can do that?

    
asked by Julian 03.10.2018 в 18:09
source

1 answer

0

I answered it in the other question you asked, the structure of that data is not the correct one to work with realtime, you are complicating a lot when you could structure it better.

But if you want to do it just put limitToLast (3) in the reference and get with getValue () those 3, and then you will have to use some separator that only takes the first part until dose: number

Ideally, under that push you create a map with all your values, I'll give you an example

Map<String,Object> infoDosis = new HashMap<>();
infoDosis.put("dosis",60);
infoDosis.put("Fecha",tufecha);
infoDosis.put("Hora y ubicacion",horayubicacion);
mDatabase.child("dosis").push().updateChildren(infoDosis);

That way the output in firebase is going to be the next one

dosis
  |__Jks29N2PkshgXz6
  |     |_dosis: 60
  |     |_Fecha: tufecha
  |     |_Hora y Ubicacion: tusdatos
  |
  |_OtroPushKey y la misma data estructurada que arriba
   .....

With that you make sure that you put under each push key 3 data, the dose, the date and the time, then with limitToLast(3) you only bring the last 3 push keys and there if you can compare and get only doses of each one.

Doc: link

    
answered by 04.10.2018 в 03:49