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

renaming files in a directory using python or R -

html - outline-style different in chrome compared to firefox and internet explorer -

Images won't display through CSS -