问题描述
这里是场景 - :$ b 一个firebase引用被创建
Firebase myRef = new Firebase(url)//在主要活动中
用户点击按钮导航到其他活动。
onPause()为主活动被调用。是否有办法销毁这个构造函数?
简单地调用finish()来完成主要的活动会不会破坏它?
Here is the scenario -: A firebase reference is created User Clicks a button navigates to other activity . onPause() for Main activity is called.Is there a way to destroy this constructor ? This reference is creating some unexpected behavior.Simply calling finish() for Main activity will destroy it or not? On the other hand, once you start attaching listeners (e.g. 这篇关于如何关闭/销毁Android中的Firebase参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
对象是对Firebase数据库中位置的轻量级引用。没有必要(也没有能力)来管理他们的生命周期。因此,@dex评论说,你可以让Java垃圾回收器来照顾它们。另一方面,一旦你开始附加监听器(例如 addValueEventListener()
),您应该使用 removeEventListener()
将它们分离到相应的生命周期事件中。另请参阅和 Firebase myRef = new Firebase(url) // In Main Activity
Firebase
objects are lightweight references to locations in your Firebase Database. There is no need (nor ability) to manage their life-cycle. So as @dex commented, you can just let the Java garbage collector take care of them.addValueEventListener()
) you should detach them in the corresponding life-cycle event with removeEventListener()
. Also see Firebase adding listeners in adapters in Android and How stop Listening to firebase location in android