aidanmack aidanmack - 1 year ago 271
Android Question

Basic Firebase database save

Anyone looking at this the below is the correct answer and I had everything setup correctly.
I still dont no what the issue is.
I was loggin in with facebook, using that to create a firebaseuser object.
and then sending the below as test data.
I've found it to be an intermittent issue. Uninstalling the app from the device and redeploying often fixes the issue.
very odd

Im actually struggling to get the example to work.

So basic.. set value....

FirebaseDatabase database = FirebaseDatabase.getInstance();
Log.d(TAG, "db ref: "+database.getReference());
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");

When I go into the database console I cant see the values I sent.
My log is returning a reference to the db though.
I've also set my rules up as public to be on the safe side.

Any ideas what I'm doing wrong?

Answer Source

Actually you are referencing a child 'message' which is logically not there,

If you want to name you root of the database simply do these steps

DatabaseReference myRef1 = FirebaseDatabase.getInstance().getReference(); //Getting root reference
myRef1.setValue("Hello, World!");

and if you want to give some value to your child in database, Make sure you have a child in your database

DatabaseReference myRef1 = FirebaseDatabase.getInstance().getReference(); //Getting root reference
DatabaseReference myRef = myRef1.child("message"); //Write your child reference if any
myRef.setValue("Hello, World!");

It will overwrite the value of your child to 'Hello World'

Make sure you added you app to firebase project and applied all required dependencies to your android project and google-service.json file in your app folder

Add these lines into Project:Gradle

dependencies {

    classpath ''
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files

Add these into App:Gradle

dependencies {

compile ''
compile ''


apply plugin: ''

Note : Do overwrite the rules in your database

    ".read": true,
    ".write": true,