Question: How to hold the XMPPTCPConnection object globally?

Hey,

I have a question, how to hold the XMPPTCPConnection object in the Android app globally?

Currently, I hold the object in the application class to get a reference in every activity.
The object is created in the AsyncTask class, because if I initialize the object in the application class, the UI thread gets blocked, until the login process is done, although I cancel the task, while the login process is running.

After the async task calls the post execute function, I reference the connection object to the application class, but if I want to disconnect the user, the server shows that the user is still online. It seems that the connection is not disconnected, or a second object exists, which holds the connection.

What is a recommanded way to hold this connection object to access it from every activity, without blocking the UI thread?

I recommend a sticky background service which manages your XMPPTCPConnection.

Thank you very much, this works for me. :slight_smile: