Home > front end >  Firestore: When do I have to remove SnapshotListeners?
Firestore: When do I have to remove SnapshotListeners?

Time:09-19

I am working on an Android App and a few of my activities are listening to a Firestore-Database with the help of the function addSnapshotListener. When an activity that called the addSnapshotListener function gets finished (by calling finish() or pressing the back button): Is the listener removed automatically or do I have to call the remove() method myself?

And what happens when I start another activity? Is the SnapshotListner of the previous activity still active or is it paused?

CodePudding user response:

Firestore never automatically removes listeners and is not aware of your app's activity lifecycle. You have to remove them yourself.

The only time a listener is automatically removed is when your application's process is terminated - all of its code ceases to run at that point.

The exception to this is when passing an Activity argument to addSnapshotListener.

  • Related