1
What happens is that I have an Activity Client where I have 2 buttons, one for registration and another for consultation, when I call the registration opens an Activity with a Tabhost with 2 fragments inside, in the query opens an Activity with listview and such, but in it has 2 buttons, one for me to edit and another to register a new Client (don’t ask me why, my boss asked so), my difficulty is the following, I am on the registration screen, I will fetch the neighborhood and call the startActivityForResult, if I called the registration screen direct from the sign up button the settResult of the Neighborhood Query returns to Intent, if I call the Customer Consultation Activity and I look for a Neighborhood, does not return setResult values.
OBS: use the same Activity to Register and Edit.
calling on startActivityForResult:
private void abrirConsBairro(View view) {
Button btnPesqBairro = (Button) view.findViewById(R.id.btnAbrirBairro);
btnPesqBairro.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent bairroCons = new Intent(getActivity(), BairroConsActivity.class);
startActivityForResult(bairroCons, 0);
}
});
}
Inside the Neighborhood Consultation:
public void selecionarBairro(View view) {
if (listaBairroCons.getCheckedItemPosition() == -1) {
Mensagens.mensagemCustomizada("Aviso!", "Selecione um Bairro primeiro!", BairroConsActivity.this);
return;
}
Bundle bundle = new Bundle();
bundle.putParcelable("objBairro", objBairro);
Intent i = new Intent();
i.putExtras(bundle);
setResult(1, i);
finish();
}
onActivityResult the registration screen:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
objCliente.getEndereco().setBairro((Bairro) data.getParcelableExtra("objBairro"));
edtBairro.setText(objCliente.getEndereco().getBairro().getNome());
edtMunicipio.setText(objCliente.getEndereco().getBairro().getMunicipio().getNome());
edtEstado.setText(objCliente.getEndereco().getBairro().getMunicipio().getEstado().getNome());
}
}
OBS²: ultilizo value 0 and 1 in an attribute to know when it is registration and when it is edition;
lavaprato, remembering that the second parameter of the
startActivityForResult
is therequestCode
and the first parameter ofsetResult
is theresultCode
. What you can do is pass a parameter within theBundle
whether it’s editing or creating instead of using 1 and 0.– Wakim
Hello Wakim, yes I understand that, but what happens is that when calling the onActivityResult of the query Activity it does not return the setResult, debugged and saw that the setResult arrow set the parameters that pass, but the other Activity does not rescue.
– lavaprato
In case it would be the
Intent data
is void or theParcelable
within it comes null?– Wakim
the Intent is coming vázio
– lavaprato
My suggestion would be to use the
getIntent
instead of instantiating a new and callingsetResult(RESULT_OK, intent)
instead ofsetResult(1, intent)
.– Wakim
I don’t know why but it worked out vlwz
– lavaprato
Ah, show, I’ll create an answer to leave to other users.
– Wakim