这是我的代码的一部分:单击按钮后,将启动新线程和与服务器的连接。如果连接成功,应用程序应该开始新的活动并结束当前活动。有人可以解释哪种方式最适合这样做吗?
transThread.submit(new Runnable()
{
public void run()
{
guiProgressDialog(true);
if(user.length() < 4) guiNotifyUser("Username must have at least 4 characters!");
else if(pass.length() < 4) guiNotifyUser("Password must have at least 4 characters!");
else if(!pass.equals(passrtp)) guiNotifyUser("Password is not same in both fields!");
else if(!isValidEmail(mail)) guiNotifyUser("Your email is not valid email address!");
else if(fname.equals("") || lname.equals("")) guiNotifyUser("All fields are mandatory!");
else {
try {
final String message = AutoDiaryHttpHelper.signUp(user, md5(pass), mail, fname, lname);
guiNotifyUser(message);
//if message equals something start new activity
}
catch(Exception e) {
e.printStackTrace();
}
}
guiProgressDialog(false);
}
});
break;