Android: closing connection when app is killed

209 Views Asked by At

I have an app that handles an XMPP connection. Now this connection is closed and resumed correctly when the main (and only) activity goes onStop(). Problem is, in the particular case when the user: -is using the app -open the recent apps list (eg square button) -kills the app

I receive no callbacks since the process gets killed (at least as far as I understand).

This is causing some weird behaviours since if the user opens the app again in a short time, there're two active connections for the user.

Aside from these connection duplicates, what is the right way to handle this specific case? Most of the answers here are quite outdated and most suggest using services to keep track of activities removed/added, but this wouldn't work on this case anyways since the service would not receive the event (the process got killed), correct? I would also run into the limitations for backround services introduced in Android 8, making the whole thing unreliable

Is there something I missed?

1

There are 1 best solutions below

2
On

I'm not sure if this would solve the problem but wouldn't you get the callback when the user opens the recent apps list with onPause().