Android XMPP connection is not persistant - asmack library even running in a separate thread

旧城冷巷雨未停 提交于 2019-12-01 12:34:52

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.

Tiji Isen

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.

class ConnectServer extends AsyncTask<Void, Void, XMPPConnection> {

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!