0

I have recently been using Firebase to transfer data across networks but the Java program I wrote will not change the data values. I have a firebase app with a tree like this.

<MY_WEBSITE>
|=>telemetry
   |=>direction : 0
   |=>speed : 0

and the code I'm using to try and write is this.

public class telem {
    public static void main(String[] args) {
        Firebase direction;
        direction = new Firebase("https://<MY_WEBSITE>.firebaseio.com/telemetry/direction");
        direction.setValue(1);
    }
}

I continued to try using both a thread.sleep and a real-time listener (separately) and the output that returned in the console said that the data change went through, however, when I checked in forge the data had not changed.

Here is the code I used:

//CREATE A FIREBASE
        Firebase fb = new Firebase("https://<MY_WEBSITE>.firebaseio.com/telemetry/direction");
        //SAVE DATA
        fb.setValue("1");
        //LISTEN FOR REALTIME CHANGES
        while(true) {
            fb.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot snap) {
                    System.out.println(snap.getKey() + " -> " + snap.getValue());
                }

                @Override
                public void onCancelled(FirebaseError error) {
                }
            });
        }

And here is the response it returned:

direction -> 1
Em Eldar
  • 686
  • 1
  • 8
  • 25
  • Since the write to Firebase happens asynchronously, you'll need to wait for it to complete. This was asked recently, so I'll look up that question and link it to yours. – Frank van Puffelen May 06 '15 at 17:42
  • Maybe this will get you going somewhere, `Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);`. – mattias May 06 '15 at 17:42
  • @Omer: I just noticed your update. Note that listeners fire straight away for local changes, so the fact that the `println` fired is no indication that it was also committed on the server. If you want to be certain of the latter, add a completion listener as documented here: https://www.firebase.com/docs/android/guide/saving-data.html#section-completion-callback – Frank van Puffelen May 08 '15 at 16:04

0 Answers0