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

邮差的信 提交于 2021-02-08 11:49:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/64196357/firestore-listener-killed-when-app-goes-in-background-for-a-long-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!