firebase

Firbase Realtime Database with Android

How to connect Realtime database with Android Application

How to implement FirebaseRealTime database in android application. Following is the steps for do it.

  1. First install firebase sdk, If you dont know how to install then following is the URL for help.

Install Firebase SDK

  1. After thet register your project in firbase console, URL of the firbase console is

Firebase Console Url

  1. After successfuly complet above to step add following dependency in you application level gradel.

compile ‘com.google.firebase:firebase-database:9.2.1’

  1. Also one more thing configure your firebase database rules. If you dont how to configure then following is the URL which help you.

Configure firebase Rules

  1. Now after all thing done, Original code is start, First retrieve your database instance throw FirebaseDatabase like following,

    FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference(“message”);

You can now create different different object of DatabaseReference for the access different node,

  1. Now you can save or retrieve data using DataBaseReference like following way,

For the save :

myRef.setValue("Demo for Save");

Read data :

myRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        // This method is called once with the initial value and again
        // whenever data at this location is updated.
        String value = dataSnapshot.getValue(String.class);
        Log.d(TAG, "Value is: " + value);
    }

    @Override
    public void onCancelled(DatabaseError error) {
        // Failed to read value
        Log.w(TAG, "Failed to read value.", error.toException());
    }
});

Note : This is the only introducation topic how to implement database in android application lost of more thing available in FirebaseRealtime database,


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow