我嘗試使用removeValue()從我的FirebaseDatabase中刪除節點,但它不起作用。奇怪的是,當我在Recyclerview中刪除節點時,節點已成功刪除。無法使用removeValue()從FirebaseDatabase中刪除節點
我使用下面的代碼在新的活動中通過recyclerview的onClick中的ref。在您的按鈕
final DatabaseReference itemRef = getRef(position);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// itemRef.removeValue();
Intent intentshowall2one= new Intent(Showcase.this, ShowProduct.class);
intentshowall2one.putExtra("S2Skey", itemRef.toString());
Showcase.this.startActivity(intentshowall2one);
,並在其他活動
key = myIntent.getStringExtra("S2Skey");
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReferenceFromUrl(key);
mDatabase.removeValue().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "deleted ", Toast.LENGTH_SHORT)
.show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT)
.show();
}
});