从Firebase获取数据并在不同的活动/片段中共享数据的最佳实践。

huangapple go评论57阅读模式
英文:

Best practice to get a list of data from Firebase and share it in different activities/fragments

问题

我正在学习如何在 Android 中使用 MVVM、Dagger2 和 Firebase,并使用 Java 正确地进行开发。我想知道以下操作的最佳实现方式:

  1. 需要从 Firebase 下载一次数据列表。
  2. 在同一个 Activity 中的多个 Fragment 中使用这些数据。

为了避免在每次创建新的 Fragment(或 Activity)时都重复下载数据的过程,有什么好的方法可以实现吗?谢谢。

英文:

I am learning to properly use MVVM, Dagger2 and Firebase on Android using java. I was wondering what would be the best way to do the following:

  1. I need to download a list of data from Firebase once
  2. Use the data in a couple of fragments in one activity.

In order to not repeat the procedure of downloading the data from Firebase when creating every new fragment (or activity). Thank you.

答案1

得分: 1

将数据加载到您的主Activity,并将其传递给任何需要该数据的Fragment或Activity。以下是如何从Activity传递数据到Fragment的方法:链接

以下是如何从Activity传递数据到另一个Activity的方法:链接

英文:

load the data into your main activity and pass it to whatever fragment or activity needs it. Heres how to pass data from activity to fragment: https://stackoverflow.com/questions/12739909/send-data-from-activity-to-fragment-in-android

Heres how to pass data activity to activity:
https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application

huangapple
  • 本文由 发表于 2020年9月21日 04:51:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63983533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定