Firestore:在OnDestroyView,OnStop或OnPause中分离快照侦听器?

时间:2019-05-02 09:07:01

标签: android firebase google-cloud-firestore

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

  • OnDestroyView
  • OnStop
  • OnPause

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

1 个答案:

答案 0 :(得分:1)

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

enter image description here

如果在方法onCreateView()中附加了侦听器,则需要在方法onDestroyView()中分离侦听器。

来自docs

  

onDestroyView()

     

在先前由onCreateView(LayoutInflater, ViewGroup, Bundle)创建的视图与片段分离时调用。

相关问题