How to add Socket (Messenger) into background

382 Views Asked by At

I created a messenger application which works with sockets. So I want to add it in background. In background the socket will hear income messages in background and show notifications. So I want to do it with WorkManager. Is it the best way and will this work? Or there are another ways to do this? Thanks. If you interested I'm using SocketCluster.

1

There are 1 best solutions below

1
Rahul On

I recommend using FCM for this. Using Sockets for maintaining persistent TCP connections can be bad from a battery perspective. If you must do this, use a foreground Service.