Firebase Realtime CRUD Operations for Android Studio.

Umesh Dananjaya
3 min readMar 6, 2021

Guys these days Firebase database is on of the most using Database that is a NoSQL database. That the one reason most of the people use Firebase realtime database. In this Blog we are going to learn about the How to operate CRUD(Create, Read, Update, Delete) operations in Firebase realtime database.

  1. Create an Android Studio project.
  2. Add Firebase realtime database to your project.

If you don’t know how to add Firebase database.Checkout this link to add Firebase database to your project.

https://umesh-dananjaya9.medium.com/how-to-connect-with-firebase-database-using-android-studio-f67836fa922f

3. Add Gradle dependencies(optional)

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.0.2'

implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
}

Some of dependencies.

4. Design your interface.(here I’m going to create Four input fields and four buttons.)

5. First You have to create a java class call employee. Right click on com.example.testfirebaseapp. (testfirebaseapp is what ever your project name)

com.example.testfirebaseapp>new>Java class

6. Declare properties of the Employee.

After-that you should create default constructor and getter and setter for that you declared properties.

Create constructor :- Right click on file click on Generate and create constructor without selecting any properties.

Create setter :- Right click on file click on Generate and create setters selecting all properties.

Create getter :- Right click on file click on Generate and create getters selecting all properties.

CRUD operations

You should create Employee object and declare and define all object type references.

I) Create

If any field is empty pop-up message to user.(example for If name is not entered)

Toast.makeText(getApplicationContext(), "Please Enter Name", Toast.LENGTH_SHORT).show();

if user enter another than the numeric number to the number Number Format Exception is used to check it.

II) show

III) Update

IV) Delete

I hope in this article you have better idea about how to use crud operations Firebase Realtime Database to Android studio.

Stay tuned. Thank you

--

--