I new here, becuase I need some help with my code. I trying to make friend request in my app. In my case I want to save my requestid, which i just created in a string. I can do it and it works perfectly fine with documentReference.getId(). But now i want to use this ID in my second if-Statement as well, but it does not get there.
if (currentstate.equals("not_friends")) {
final Map<String, String> request = new HashMap<>();
request.put("yourid", yourid);
request.put("otherid", otherid);
request.put("Type", "req_send");
fStore.collection("request").add(request).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText(otherProfile.this, "Versendet", Toast.LENGTH_SHORT).show();
currentstate = "req_send";
add.setEnabled(true);
add.setText("Anfrage löschen");
String requestid = documentReference.getId();
Toast.makeText(otherProfile.this, requestid, Toast.LENGTH_SHORT).show();
}
});
}
if (currentstate.equals("req_send")) {
fStore.collection("request").document(requestid).delete().addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(otherProfile.this, "Gelöscht", Toast.LENGTH_SHORT).show();
add.setText("Freundschaftsanfrage versenden");
currentstate = "not_friends";
add.setEnabled(true);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(otherProfile.this, "Nö", Toast.LENGTH_SHORT).show();
}
});
}
I add the data in the first If statement, but now the button changes and i want to delete the friend request in the second If Statement. So i want wo delete the data again in my Database. But the ID requestid does not save from the first statement, so I do not get acess the right data, which I wnt to delete.