Aditya Rana
Aditya Rana

Reputation: 94

Do firebase connections remain active even when I finish the Activity?

I am creating a chat application where I want to show the user's current online/offline status. For that, I am using Firebase onDisconnect() event.
I am thinking to initialize this in Splash Activity rather than into individual activities in my app. But the problem is I finish the Splash Activity.
So I just want to know whether the Disconnect event will be called on finishing the activity or not?

Upvotes: 1

Views: 167

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317487

Disconnect handlers trigger on the server when the socket connection to the server is closed. That doesn't necessarily have anything to do with an activity finishing.

Android will eventually close the connection when the app process is killed, which will happen after some time, if it's not displaying any activities, and if it doesn't have any foreground services running. Again, this is not necessarily the same moment when some arbitrary activity finishes. You should read the Android documentation to understand how Android deals with the process lifecycle.

If you want to take control of the moments when the SDK connects and disconnects, you should call goOffline() to close the connection. You can then ask the SDK to connect again by calling goOnline().

Upvotes: 3

Related Questions