Android Firebase Database: Selecting One Information Without an Event Listener

The following database hierarchy is currently in the Firebase database console.

enter image description here

I use the following code to enter data into a firebase database.

public void createRecordInDB(PlaceListItem placeListItem) { mDB= FirebaseDatabase.getInstance().getReference(); mListItemRef = mDB.child("Places"); for(int i = 0; i < placeListItem.getResults().size(); i++) { // Create new List Item at /listItem String placeId = placeListItem.getResults().get(i).getPlaceId().toString(); String key = placeId; PlaceDBModel placeDBModel = new PlaceDBModel(); placeDBModel.setPlaceName(placeListItem.getResults().get(i).getName()); placeDBModel.setVicinity(placeListItem.getResults().get(i).getVicinity()); placeDBModel.setLattitude(placeListItem.getResults().get(i).getGeometry().getLocation().getLat().toString()); placeDBModel.setLongitude(placeListItem.getResults().get(i).getGeometry().getLocation().getLng().toString()); placeDBModel.setPlaceID(placeId); if(isItWorking(key)) placeDBModel.setWorkingOrNot("Working"); else placeDBModel.setWorkingOrNot("Not Working"); HashMap<String, Object> result = new HashMap<>(); result.put(key, placeDBModel); mListItemRef.updateChildren(result); } 

Look, when I first download data from a web service, I just enter all the data into a firebase database. Now on one screen of my application (clicking a button) I can update some data, in particular node. Now, when I return to the previous screen again and load the data from the web API, it overwrites all the data in the firebase database. I need to save the changed values, as it was during the button click. So I want to read this data in node, if it works, then set the value "Work" to "Still not working". Hope this clarifies my request.

+5
source share
1 answer

Reading data after

"In some cases, it can be useful to call the callback once and then delete it immediately. We created a helper function to make this easy:"

https://firebase.google.com/docs/database/admin/retrieve-data#pln

0
source

Source: https://habr.com/ru/post/1259829/


All Articles