I am currently working on an application that uses asmack lib to connect to a XMPP Server. This application basically includes Sending/receiving messages, changing statuses, etc.
At the moment, the XMPP connection lives inside the application and isn't in some sort of background service. So now I'm wondering, is it better to keep the connection alive using a service or just keeping the connection alive when my application is actually running.
This is taking in consideration that I want to stay connected to the XMPP Server the entire time when my application is running background and when user come back to any activity having XMPP connection. i did like this, if it comes to main activity ( means where i am connecting with credentials ) re-connecting the XMPP connection with same credentials. but i am facing problem that when i stay for some time in contacts view, the connection is getting closed after some time if that activity resumes back getting foreclose at connection ( i.e null pointer exception ).Here it is not possible to re-connect the connection.
So in a way I'm asking if it's better to (re)connect/log-in as soon as my Activity is brought to the foreground/started or is it better to connect once inside a service and just keep this connection alive?
If service creation is better way, How to create a from fragments and how to create XMPP connection and i have to do log-in and log-out by using buttons .how to maintain these options in service.
Thanks in advance,