Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close/destroy a Firebase reference in android?

Here is the scenario -:

A firebase reference is created

Firebase myRef = new Firebase(url)  // In Main Activity

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?

like image 760
user3450804 Avatar asked Apr 09 '16 18:04

user3450804


1 Answers

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.

On the other hand, once you start attaching listeners (e.g. 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

like image 90
Frank van Puffelen Avatar answered Nov 02 '22 23:11

Frank van Puffelen