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

Updated2
Is there an easy way to set removeQuery to null?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With