android - Should I use AsyncTask to establish an XMPP connection? -


i connecting xmpp server in android using smack. here code:

 static void openconnection() {         try {             if (null == connection || !connection.isauthenticated()) {                 xmpptcpconnectionconfiguration.builder configuration = xmpptcpconnectionconfiguration.builder();                 configuration.sethost(server_host);                 configuration.setport(server_port);                 configuration.setservicename(service_name);                 configuration.setusernameandpassword(new tinydb(context.getapplicationcontext()).getstring("username"), new tinydb(context.getapplicationcontext()).getstring("password"));                 configuration.setdebuggerenabled(true);                  connection = new xmpptcpconnection(configuration.build());                 connection.setusestreammanagement(true);                 connection.setusestreammanagementresumption(true);                  reconnectionmanager reconnectionmanager = reconnectionmanager.getinstancefor(connection);                 reconnectionmanager.enableautomaticreconnection();                 reconnectionmanager.setreconnectionpolicy(reconnectionmanager.reconnectionpolicy.random_increasing_delay);                  connection.connect();                 connection.login();             }         } catch (xmppexception xe) {             xe.printstacktrace();         } catch (smackexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }     } 

so when call openconnection() should in asynctask or not necessary? little confused.

when call openconnection() should in asynctask or not neccesary?

shortly, yes. related networking should moved another thread avoid blocking main thread. hence doinbackground() of asynctask runs on thread, should call function.


Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -