我正在尝试从线程中获取一些信息,但我不知道如何。我从来没有使用过线程,我的问题是关于这个的。
我有一项活动,它使用一个线程的 web 服务。在此之后,如果结果为真,我想执行一些操作,如果结果为假,则执行其他操作。
我无法修改线程中的局部或全局变量,所以我不知道该怎么做。我不想在线程中抛出意图。
有没有办法返回这个结果?谢谢
这是我的活动代码:
public class RegisterActivity extends Activity {
//Constantes para la invocacion del web service
private static final String NAMESPACE = "http://webservice.proyecto";
private static String URL="http://192.168.1.34:8080/BDManejador/services/conexion?wsdl";
private static final String METHOD_NAME = "nuevo_usuario";
private static final String SOAP_ACTION ="http://ws.webapp.ejemplo/nuevo_usuario";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
}
public void goMainMenu (View v) {
final EditText email = (EditText)findViewById(R.id.user);
final EditText password = (EditText)findViewById(R.id.pass);
EditText repeat_password = (EditText)findViewById(R.id.rpass);
// COMPROBAR EMAIL VALIDO
if((email.getText().toString().length() == 0) || (!email.getText().toString().contains("@")) ||(!email.getText().toString().contains("."))) {
Toast toast= Toast.makeText(getApplicationContext(), "DIRECCIÓN DE CORREO ELECTRÓNICO NO VÁLIDA", Toast.LENGTH_LONG);
toast.show();
}
else {
// COMPROBAR CONTRASEÑA REPETIDA IGUAL
if((password.getText().toString().compareTo(repeat_password.getText().toString()) == 0) && (password.getText().toString().length()!=0)) {
// USAMOS EL WEBSERVICE
Thread networkThread = new Thread() {
@Override
public void run() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("email", email.getText().toString());
request.addProperty("pass", password.getText().toString());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
final SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
final boolean str = Boolean.parseBoolean(response.toString());
if (str) {
Log.v("MYAPP", "INSERTADO");
}
else
Log.v("MYAPP", "NO INSERTADO");
}
catch (Exception e) {
e.printStackTrace();
}
}
};
networkThread.start();
//ESPERAR QUE TERMINE LA OPERACION
try {
networkThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
//LANZAR LA NUEVA ACTIVIDAD
Intent intent = new Intent(RegisterActivity.this, MenuActivity.class);
startActivity(intent);
}
else {
Toast toast= Toast.makeText(getApplicationContext(), "LAS CONTRASEÑAS DEBEN SER IGUALES", Toast.LENGTH_LONG);
toast.show();
}
}
}
}
所以我想在变量 booleanstr
为真时抛出我的意图。
有人可以帮忙吗?