CONNECTIVITY_CHANGED does not fix the problem. I have the same problem as described above. What I recognized is, that this connection is still ok, I checked with an timer every x seconds. Connection is connected and authenticated, both requests are true. The strange thing is, I implemented a Ping Manager, although the isConnected() and isAuthenticated() requests gave me true, the ping manager throws a ping failed exception and I cannot send to my online client, which worked before.
After some time, sometimes minutes, sometimes hours, the connection get lost, but returns true. There is anything wrong I assume, but can´t get what.
What I´ve found is, that it also depends on the XMPP Server that You use. I am using one of the public servers, so I don´t know exactly how it is implemented. Some servers seem to cut the connection between users, but not the connection to the server. Some does this not. Also, implement the XMPP Connection in a service and return REDELIVER_INTENT to onStartCommand() to be sure the service is alive as long as possible.
This way decreased the times of disconnecting to the user and now I have much less problems with that.
Another hint is, some devices have an energy save option (same as task killers). Here You can set properties to the app, that they don´t get killed if device go to sleep. Anyway, there is no possibility to do this programmatically but with root permissions. So You have to give this hint to the users.
Just for information: Also WhatsApp has this problem, I detected this by myself. If I don´t use my device a long time, some hours, and then I wake it up, I get messages from friends via WhatsApp, and they said, they sent it hours before.
I think with START_STICKY You are going the wrong way. It is really important to redeliver the used intent with START_REDELIVER_INTENT. Another possibility is, to start the service as foreground service but then You will always have an icon and notification in the notification bar. How do You have implemented the connection inside service? Do You have binded the service? That´s what I have tried first, but then I get away from binding the service to my activities because the service get killed if activities get killed with onBind().