我有一个 ArrayList
存储在 Firestore
中。
我在 Fragment A 中有一个 RecyclerView
,显示每个人的基本信息。
我有一个 onClickListener
,它用 Fragment B 替换 Fragment A ,并将单击项目上的人员的 UID 传递给 Fragment B< /strong> 也是如此。
我使用 Fragment B 的目标是通过某种方式使用 UID 从 Firestore
获取数据来显示所点击的 Person 项目的所有详细信息(以及添加更多数据的选项)代码>.
我的问题是,我是否应该为需要相同 Firestore
的每个 Fragment
实例化一个 Firebase Firestore
?或者我可以将 Person 对象作为一个包传递(尽管我不确定我所做的任何更改是否会反映在 Firebase 上)。
我认为这是一个非常昂贵的过程,我不确定我的替代方案是什么。
I have an ArrayList<Person>
stored in Firestore
.
I have a RecyclerView
in Fragment A displaying the basic info of each person.
I have an onClickListener
that replaces Fragment A with Fragment B and passes off the UID of the Person on Item clicked to Fragment B as well.
My goal with Fragment B is to display all of the details of the Person item clicked (and an option to add some more data) by somehow using the UID to get my data from Firestore
.
My question is this, should I instantiate a Firebase Firestore
for every Fragment
that I need that same Firestore
in? Or can I pass off the Person object as a bundle (though I'm not sure if any changes I make reflect on Firebase).
I thought it was a very costly process and I'm not sure what my alternatives are.
发布评论
评论(1)
您将始终得到相同的对象。
如果 Person 类实现 Parcelable<,则可以将数据传递给第二个片段/a>.如果它实现了 Parcelable,您可以将 person 对象添加到捆绑包中并将其发送到另一个片段这样。
如果“实例化 Firestore”实际上是指从 Firestore 检索数据,则本地 Firestore 缓存您的应用正在使用的数据副本,因此片段 B 将从本地缓存中检索数据。
You will always get the same object.
You can pass off the data to the second fragment if the Person class implements Parcelable. If it implements Parcelable you can add the person object to a bundle and send it to the other fragment this way.
If by "instantiating Firestore" you actually mean retrieving your data from Firestore , Firestore locally caches a copy of the data that your app is using, so fragment B will retrieve the data from the local cache.