Skip to content Skip to sidebar Skip to footer

Android Xmpp Connection Is Not Persistant - Asmack Library Even Running In A Separate Thread

I am developing an Android chat app which uses asmack library. What I observe is that the XMPP connection beocmes disconnected after a particular interval of time. ( This also vari

Solution 1:

After a long struggle, here are my observations and I was able to find a solution to the issue. Any feedback about my solution is welcome

The Edit holds the answer.

I simply modified the code from Runnable to a Thread

When the code which connects to the chat server was in a Runnable, I got a android.os.NetworkOnMainThreadException. For some reason, I am not able to find the stack trace of NetworkOnMainThreadException. The ConnectionConfiguration was carrying the NetworkOnMainThreadException when the connection is made using a Runnable.

Hope this helps someone who face a similar issue to mine. I sincerely thank @Flow for his effort in helping me resolve this issue. Your smack work is very commendable and a blessing for the android community.

See the image attached for the exception. enter image description here

Solution 2:

It will be better to use AsyncTask for connection in your code rather than using Thread.It is not recommended to use Thread in Android.Try AsyncTask, it is used for all connection related purposes.

classConnectServerextendsAsyncTask<Void, Void, XMPPConnection> {

}

Post a Comment for "Android Xmpp Connection Is Not Persistant - Asmack Library Even Running In A Separate Thread"