Kaitlyn Hanrahan
Kaitlyn Hanrahan

Reputation: 789

How to remove firebase event listener without a reference to it?

My situation is I have some firebase database event listeners that I start when the app starts. These keep user data in sync across devices. I also have a service that will very occasionally be called. It uploads a lot of data. I want to turn off the listeners when I start the service so they don't go crazy. It's the same data; I can't just use different locations.

My question is how can I close them? I figure I need to either close the listeners without a reference to them (doesn't seem possible that I've found) OR maintain a reference to the ChildEventListener objects somehow AND access that reference from the Service.

If it's any help, both the service and data event listeners are being initiated right after the application starts. Is there a way to pass non-primitive data to the Service? Intent extras are 'copies' so that seems like a dead end. Do I make a static reference to the ChildEventListeners in the Application class? How would I best do that if that's the way to go?

Upvotes: 0

Views: 441

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317968

There is no way to stop a listener if you don't have the actual ValueEventListener or ChildEventListener object to pass to removeEventListener(). You'll have to store them in some sort of global or singleton so that they can be accessed from the relevant parts of your program that needs to use them.

Upvotes: 1

Related Questions