【问题标题】:Firestore: Detach snapshots listeners in OnDestroyView, or in OnStop or OnPause?Firestore:在 OnDestroyView 或 OnStop 或 OnPause 中分离快照侦听器?
【发布时间】:2019-05-02 09:07:00
【问题描述】:

根据https://www.tutorialspoint.com/android/android_fragments.htm,可以使用三个处理程序来从 Firebase Cloud Firestore 数据库中分离我的快照侦听器:

  • OnDestroyView
  • OnStop
  • 暂停

我认为最方便的方法是在OnPause 中分离它,因为该文档指出“系统调用此方法作为用户离开片段的第一个指示。”。我说的对吗?

【问题讨论】:

    标签: android firebase google-cloud-firestore


    【解决方案1】:

    这取决于您附加监听器的生命周期。以下是片段生命周期:

    如果监听器是在方法onCreateView()中附加的,那么你需要在方法onDestroyView()中分离监听器。

    来自docs

    onDestroyView()

    当先前由onCreateView(LayoutInflater, ViewGroup, Bundle) 创建的视图已从片段中分离时调用。

    【讨论】:

      猜你喜欢
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 2020-02-24
      • 1970-01-01
      • 2021-07-29
      • 2018-12-11
      • 2021-04-07
      相关资源
      最近更新 更多