android java add new record to firebase firestore

Solutions on MaxInterview for android java add new record to firebase firestore by the best coders in the world

showing results for - "android java add new record to firebase firestore"
Pénélope
30 Aug 2020
1Map<String, Object> city = new HashMap<>();
2city.put("name", "Los Angeles");
3city.put("state", "CA");
4city.put("country", "USA");
5
6db.collection("cities").document("LA")
7        .set(city)
8        .addOnSuccessListener(new OnSuccessListener<Void>() {
9            @Override
10            public void onSuccess(Void aVoid) {
11                Log.d(TAG, "DocumentSnapshot successfully written!");
12            }
13        })
14        .addOnFailureListener(new OnFailureListener() {
15            @Override
16            public void onFailure(@NonNull Exception e) {
17                Log.w(TAG, "Error writing document", e);
18            }
19        });
20