Reputation: 5
Im using firebase android and I have a problem while getting inside other acitivy to delete few childs. The method onChildRemoved
called when I inside the activity the method is at. I undrestand that.
However I don't undrestand why I returned back to the method call once I used Intent to get out from the activity where the method onChildRemoved
is in.
How can I disable calls from onChildRemoved
method when being in other activity?
Upvotes: 0
Views: 113
Reputation: 599716
It sounds like you're using addChildEventListener
to attach the listener, which means that the listener remains active until you explicitly remove it. Changing activities does not automatically remove the listener.
What you can do is remove the listener on for example the onPause
method, by calling the removeEventListener
method on the same reference/query that you added it to.
So for example if you add it with something like:
listener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
...
}
ref.addChildEventListener(listener);
Then you can later remove it with:
ref.removeEventListener(listener);
Upvotes: 1