How to Delete Data from Firebase Realtime Database in Android?
In this article, we will see How to Delete added data inside our Firebase Realtime Database. So we will move towards the implementation of this deleting data in Android Firebase.
What we are going to build in this article?
We will be showing a simple AlertBox when the user long clicks on the item of RecyclerView. It will have two options. (Delete and Cancel) .When the user clicks on delete it will simply delete that value. You can refer to How to Save Data to the Firebase Realtime Database in Android to learn how to save data in Firebase.
Note: You can use Hashmap to save data in firebase.
Further you can also directly add data in firebase like shown below
Step By Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
Step 3: Working with the DModel.java file
Go to the DModel.java file and refer to the following code. Below is the code for the DModel.java file.
Step 4: Working with the DAdapter.java file
Go to the DAdapter.java file and refer to the following code. Below is the code for the DAdapter.java file
Step 6: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.