What happens is that I have an Activity Client where I have 2 buttons, one of register and another of query, when I call the register 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 (do not ask me why, my boss asked so), my difficulty is as follows, I'm on the registration screen, I go to the neighborhood and I call the startActivityForResult, if I called the register screen directly from the register button, the SetResult of the Neighborhood Query returns to Intent, if I call the Client Query Activity and I search for a Neighborhood, I do not returns the values of the setResult.
NOTE: I use the same activity to Register and Edit.
calling the 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);
}
});
}
Within the Neighborhood Query:
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 of 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());
}
}
NOTE: I use value 0 and 1 in an attribute to know when it is registered and when it is edited;