5

Right now, following is my database hierarchy in Firebase Database console.

enter image description here

I am using following code to enter data into 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);

        }

See when I load data from web service first time, I simply enter all data into firebase database. Now in one screen of my app(a button click), I can update some data in particular node. Now when I again back to previous screen and it loads data from web API, it overwrites all data into firebase database. I need to remain changed values as it was at the time of button click. So I want to read that particular data in node, if it is Working then set value "Working" else "Not Working". I hope this will clarify my query.

koceeng
  • 2,169
  • 3
  • 16
  • 37
Manish Dubey
  • 4,206
  • 8
  • 36
  • 65
  • please share your entire code of this activity. – Abhinav Raja Nov 16 '16 at 14:38
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export JSON link in your Firebase Database console. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Rosário Pereira Fernandes Feb 04 '17 at 21:35

1 Answers1

0

Reading Data Once

"In some cases it may be useful for a callback to be called once and then immediately removed. We've created a helper function to make this easy:"

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

Niraj
  • 517
  • 1
  • 5
  • 14