How to delete data from Firebase in Android Studio

Android Studio is one of the software The best Android application developer today. This is due to the many features that are supported by Google. In the previous tutorial, we discussed how to connect Android Studio to Firebase and add data to Firebase. This time we will discuss how to delete data from Firebase in Android studio.

Also read:

It was done in the previous tutorial shape with entrance Username, Name and number WL. This time we’re going to add more, namely Username and button to remove Username. When the button is pressed, the data Username on Firebase will be deleted. Here is the tutorial.



1. Write down the following code xml-activity_main.xml


When button Delete is pressed, then method click2 is executed.

2. Then continue Main adds a couple of changes, namely instantiation text4 what is entry Username new and method click2, which is used to delete data on Firebase.

Write down the following code

package com.example.abifirmandhani.inwepo;  import android.content.Intent; import; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView;  import; import;  public class MainActivity extends AppCompatActivity {      	//instansiasi database firebase     	FirebaseDatabase database ;     DatabaseReference myRef;     EditText text1;     EditText text2;     EditText text3;     EditText text4;        @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         database = FirebaseDatabase.getInstance();         text1 = (EditText) findViewById(;          text2 = (EditText) findViewById(;         text3 = (EditText) findViewById(;         text4 = (EditText) findViewById(;        }      	//method tambah user     	public void Click1(View view){          //Referensi database yang dituju         myRef = database.getReference("User").child(text1.getText().toString());          //memberi nilai pada referensi yang dituju         myRef.child("name").setValue(text2.getText().toString());         myRef.child("NoHp").setValue(text3.getText().toString());       }      //Hapus user     public void Click2(View view){          //inisiasi database reference         myRef = database.getReference("User").child(text4.getText().toString());          //hapus data         myRef.removeValue();       }  }

Databases R.the reference is child from user, where child of the user according to the wishes of the user.

Then delete the required data with method removeValue ().

3. Run the application by clicking the play icon in the Toolbar Android Studio and select device that you will use for testing.

4. Here is a picture where Database before something is deleted.

5. Then the application tries to delete data Username aaa.

6. In the picture seen that data Username aaa was successfully deleted, leaving behind cupacup and wikipedia.

7. Will try again to delete Username Cup.

8th Dan Username cupacup was also successfully deleted and left Username Wikipedia.

Complete. The above tutorial is a simple example of clearing data on Firebase. You can expand it again by changing some code in the reference database.

Leave a Reply

Your email address will not be published.