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

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -