So vermeiden Sie das Überschreiben von Daten in firebase

Dies ist mein Code zum Hinzufügen von Datensätzen in Firebase. es gibt eine Variable außerhalb namens restauCount mit dem Wert (int) 1

public void sendMessage(){

    int restauCount = 1;
    String identifier ="Restaurant" + restauCount;
    Firebase userRef = firebaseRef.child("Caloocan");
    EditText nameInput = (EditText) findViewById(R.id.nameTxt);
    String name = nameInput.getText().toString();

    EditText locInput = (EditText) findViewById(R.id.locationTxt);
    String location = locInput.getText().toString();

    EditText typeInput = (EditText) findViewById(R.id.typeTxt);
    String foodtype = typeInput.getText().toString();
    if (!name.equals("")){
        Map<String, String> caloocan = new HashMap<String, String>();
        caloocan.put("resname", name);
        caloocan.put("resloc", location);
        caloocan.put("foodtype", foodtype);

        Map<String, Map<String, String>> users = new HashMap<String, Map<String, String>>();
        users.put(identifier,caloocan);

        userRef.setValue(users);
        restauCount++;
    }
}

Wenn ich die sendessage () erneut starte. Ich tippe die Felder ein und wenn ich auf HINZUFÜGEN klicke, welches die sendMessage ist, wird sie in FireBase hinzugefügt, jedoch wenn ich neue Daten hinzufüge. ES ÜBERSCHREIBT DIE ALTEN EINGEGEBENEN DATEN? WIE KANN ICH MEHRERE DATEN IN FIREBASE HINZUFÜGEN, OHNE DIE DATEN ZU ÜBERSCHREIBEN? restauCount wurde erstellt, um die Anzahl der von mir eingegebenen Restaurants zu erhöhen.

Antworten auf die Frage(8)

Ihre Antwort auf die Frage