Muhammad Faisal Amin avatar

Delete Firebase Data | Android App Development | Lecture#47 | Hive Learners

faisalamin

Published: 17 Aug 2022 › Updated: 17 Aug 2022Delete Firebase Data | Android App Development | Lecture#47 | Hive Learners

Delete Firebase Data | Android App Development | Lecture#47 | Hive Learners

𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼

Hi dear Hive Learners, I hope you all are well. In lecture 46 we learn how to process the retrieved data from the firebase real-time database and then we add this data in a model class and use this model class in an adapter to show the data in a listview. We also successfully run the app and it was working like charm. Today we will learn how to delete data from the firebase database by using the button in the listview. So let's get started.

alt

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • How to delete data from Firebase real-time database

Assignment

  • Delete data on a button click

Procedure

We already has a delete button in our listview and also have a listener for it. We need to get to know what child we are deleting and write the code according to it. We will also implement the complete listener to sow delete successful or failed messages on the screen. We implement the listener interface in the Fragment When we move the code. That interface will not work in the Fragment so we will use the onclicListenere in the Adapter class.

alt

Now we need to first get the child that we want to delete on the button click. We want the parent node and the child inside it can be deleted automatically. We are using the Firebase Auth id as the parent key. So we can get and use the Firebase uid. Using parent Firebase uid will not allow us to store more than one data for a user. We need to use the PushKey and we will do it in the next lecture. This time we are simply learning how to delete the data in firebase.

alt

We can implement the task complete listener to show the success or failure message. I add the new data in the database so we can save the data via uid.

alt

We hardcode the username value which is why we get the My Account in the username field. Here we now have two children in the sending reference.

alt

Now press the delete button on this child and check if the data is deleted from the database or not.

alt

alt

Data is deleted but we have not notify the adapter that data is changed so we need to do so. We also need to change the Listener type from Single Listener to a regular Listener so that the database can get the change and update the POJO class. I also change the code in the Transfers_Fragment to store the account_number correctly.

alt

alt

Let's try to add and delete the item again.

alt

alt

hl_divider.png

Thank You

hl_footer_banner.png

Leave Delete Firebase Data | Android App Development | Lecture#47 | Hive Learners to:

Written by

Android | Python | Software Engineer

Read more #hive-153850 posts


Best Posts From Muhammad Faisal Amin

We have not curated any of faisalamin's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Muhammad Faisal Amin