Let's say I have an Arraylist named PersonList stored in Firebase FireStore. Every Person has a bunch of attributes (name, contact number, email, etc.).
I have RecyclerView displaying each person's name. That RecyclerView is stored in Fragment A. When I click on an Item in Recycler View, I use Fragment Manager to replace Fragment A with Fragment B. Fragment B lets me view all of that person's data (not just his name), plus maybe add or edit some data as well. Currently, I am able to get that person's name from Fragment A and pass it off as an argument and display it in Fragment B.
Now I plan to get the position of that Person Object onClick in Fragment A, call another instance of PersonList and use position to get all of a particular person's data (not just his name) displayed in Fragment B. I also want to be able to edit that data in Fragment B and have the changes reflected in my Firestore. My question is this: should I keep on replacing Fragment A with Fragment B? Or should I use intent instead? I am new to Java and AndroidStudio and am just feeling my way through, any other insights or opinions with my plan are welcome.
CodePudding user response:
To answer your questions:
My question is this: should I keep on replacing Fragment A with Fragment B?
That's a way to go from one fragment to another. However, a more convenient way would be to use navigation between fragments, which is a component of Android Architecture Components.
If you understand Kotlin, here is a useful article where you can see how to interact with Firestore:
Or should I use intent instead?
Intents are used for navigation between activities, not fragments.