I am watching a video to create a simple app(just to practice concepts) where the user enters the title and their thoughts. This data will get sent to Firestore.
However, I was confused on the part where I send data through a HashMap:
Map<String, Object> data = new HashMap<>();
data.put(STRING_TITLE, title);
data.put(STRING_THOUGHTS, thoughts);
The title and thought are basically just the string values of the user's input for the title and thought.
String thoughts = edtThoughts.getText().toString().trim();
String title = edtTitle.getText().toString().trim();
After that, all I'm doing is just passing it into the journalRef: journalRef.set(data)
where journalRef is just the DocumentReference of my database:
private FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference journalRef = db.collection("Journal").document("MyThoughts");
My question is: Why do we pass data as Map<String, Object>
instead of Map<String, String>
. Isn't the title and thoughts just the user's input as a String value?
Edit:
Also, when I go to Firestore, why does it show the thoughts and title as a String rather than an Object(which was declared in the HashMap)?
Thanks!