Using the Asynctask, you can put login inside.
Because this is my own project code, so I try not to send too many strong coupling code
Private Integer Login () {String name = Util.readpre (context, App.getloginname (), Goloveapp.username, ""); String pwd = util.readpre (context, App.getloginname (), Goloveapp.password, ""); try {xmppconnection connection = Xmppconnectionmanager.getinstance (). getconnection (); Connection.connect (); Connection.login (name, Util.MD5 (PWD)) ;//processing Offline message offlinemsgmanager.getinstance (context). Getofflinemsg (connection); Connection.sendpacket (New Presence ( Presence.Type.available)); return goloveapp.login_seccess;} catch (Exception e) {if (e instanceof xmppexception) {xmppexception XE = (xmppexception) e;final xmpperror error = XE.GETXMP Perror (); int errorCode = 0;if (error!=null) {ErrorCode = Error.getcode ();} if (errorcode==401 | | errorcode==403) {return goloveapp.login_error_account_pass;} Else{return goloveapp.server_unavailable;}} Else{return goloveapp.login_error;}}}
Android Asmack Login