E. Sun
E. Sun

Reputation: 1344

Firestore listener killed when app goes in background for a long time

In my app I'm listening for a Firestore query whenever the user signs in. After the app goes in background for some time, the listener gets cancelled and the client doesn't get notified of any new changes.

How do I know if a listener has been cancelled by the SDK? What's the proper way of handling this?

Upvotes: 5

Views: 2061

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599876

On most operating system this is done automatically by the system itself, in order to preserve battery life. Whether it is possible to detect this situation, and how, depends on the OS.

In most cases it is better to depend on another mechanism to deliver updates to an app that is not actively being used, such as Firebase Cloud Messaging - which you can call from for example Cloud Functions to deliver messages to backgrounded apps. For an example of this, see the Firebase documentation on notifying users when something interesting happens.

Upvotes: 0

Related Questions