I am new to Android and working on a project where I need to get the input from users through multiple activities and then add that data to the Firebase Firestore but the problem I m facing is that the data is saved in different documents IDs but I want it to be in the same document id?? So that I can retrieve the data at once. Please guide me on how can I achieve that? Thank you in advance.
CodePudding user response:
Use Fragment for showing UI and use SharedViewModel for saving data at one place.
Using activity, pass data from one activity to another and merge and pass to another until last activtity.
Create table for complete data and access and update it in every activity and at last, get table data and upload to firestore.
These are the few generic approach for sharing data in activities and fragments.
CodePudding user response:
When you're calling CollectionReference#add(Object data) or DocumentReference#document() without passing any ID, it will always assign a unique document ID automatically. If you do one of these operations in different activities, then you'll end up always having different document IDs.
If you need to write data to the same document from different activities, you either save the data under a fixed (known) document ID, or you pass the first generated ID from one activity to another, as I also mentioned in one earlier question of yours.