Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting auto key node from firebase android

I'm not sure if I'm doing this right but I'm creating a Query to get the auto-generated key that is stored in firebase. I want to delete this key from firebase. I'm wondering if this the right process? Like is it possible to just call removeValue() on the query or have to use Datasnapshot? My code is as follows. All it does is gets the auto-generated key and prints it.

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); String removeQuery = ref.child("EventData").push().getKey(); System.out.println(removeQuery); Log.d(TAG,"Remove Query was called !!!!!!!!!!!!");

Updated1 enter image description here

Updated2

Is there an easy way to set removeQuery to null?

like image 333
Mark_rath Avatar asked Jul 21 '26 04:07

Mark_rath


1 Answers

Here:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); 
String removeQuery = ref.child("EventData").push().getKey();

You are creating a new key and storing it inside a variable. You can do that in the beginning (when storing data to the database), add data to Intent:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); 
String removeQuery = ref.child("EventData").push().getKey();
Intent intent = new Intent(getBaseContext(), Activity.class);
intent.putExtra("key", removeQuery);
startActivity(intent);

then later in the other activity you can delete like this:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); 
String key = getIntent().getStringExtra("key");
ref.child("EventData").child(key).removeValue();
like image 58
Peter Haddad Avatar answered Jul 22 '26 19:07

Peter Haddad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!