Activity does not open after thread

Asked

Viewed 72 times

1

I’m on an Android project and I have an Activity that doesn’t open, well starting from my main Activity I already have a button that calls another and everything occurs as expected I can make the transition from one to another without problems but I do not know what happens with this other that I call no more appears, I have already exchanged it with the one that is being called and then it appears, much more we go to the events so that if someone can help me... I have a WS and in my main Activity two fields user and password, When I click on the login button I call a thread that will access WS if I can log in then I have to call Sincronizaractivity, this has the purpose of doing a synchronization or import some entries but it does not appear and even in the logcat something indicates an error. Well a little code might explain it better.

private void login(String login, String senha) {
    soap = new SoapObject(namespace,METHOD_NAME ); 

    PropertyInfo p1 = new PropertyInfo();
    PropertyInfo p2 = new PropertyInfo();
    p1.setName("Usuario");
    p1.setValue(login);
    p1.setType(String.class);
    p2.setName("Senha");
    p2.setValue(senha);
    p2.setType(String.class);

    soap.addProperty(p1);
    soap.addProperty(p2);

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(soap);
    transporte = new AndroidHttpTransport(URL);

    progress = ProgressDialog.show(MainActivity.this, "Logando", "Aguarde...", true, false);

    Thread th = new Thread(MainActivity.this);
    th.start();
}

@Override
public void run() {

    try {

        transporte.call("", envelope);
        //resposta = (SoapPrimitive) envelope.getResponse();
        objRetorno = envelope.getResponse();

        handler.sendEmptyMessage(0);

    } catch (Exception e) {
        Log.e("Erro", "Erro: "+ e.getMessage());
        finish();
    }

}

private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        progress.dismiss();

        String[] parts = objRetorno.toString().split("#");

        if (Boolean.parseBoolean(parts[0])) {
            edtRetorno.setText("Ok ! "+parts[2]);
            criarsessao(parts);
        } else {
            edtRetorno.setText("Acesso negado! "+parts[1]);
        }

    }
};

Well and to finish the method that calls Activity

private void criarsessao(String[] dados){
    sessaoUsuario = new SessaoUsuario();

    sessaoUsuario.setUsuario(edtUserName.getText().toString());
    sessaoUsuario.setSenha(edtPassWord.getText().toString());
    sessaoUsuario.setId(Integer.parseInt(dados[1]));
    sessaoUsuario.setNome(dados[2].toString());

    sessaoUsuarioService.criarSessao(sessaoUsuario);

    config = confService.BuscaporId(1);

    if (config.getSinc().toString() == "S"){
        Intent intent = new Intent(MainActivity.this, SincronizarActivity.class);
        startActivity(intent);
    }

}

So if anyone can give me a helping hand I’d appreciate it.

  • Use debug to know what happens, check the methods criarsessao and the method onCreate of Activity SincronizarActivity to thresh. We have two probable options, 1st one of the conditions to open the new activity is not being true, or 2nd some error happens in onCreate of the activity to be called

  • Dear good afternoon, I went out yes debugging everything, but the problem is in If where I test the config.getSinc() there I am using the operator ==, I changed and put the equals method and then I fixed the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.