You can use the method startActivityForResult()
which allows a Activitya call a Activityb and receive a return from it.
To do this, in your Activitya call on the Activityb using the method startActivityForResult()
. An example:
Intent i = new Intent(this, ActivityB.class);
/*
Crie seu Bundle e coloque dados
*/
startActivityForResult(i, 1); // O '1' é um id para a operação
In his Activityb do the normal procedure of taking the data from Activityaand when you return them write the following code on Activityb:
Intent intentRetorno = new Intent();
intentRetorno.putExtra("resultado", dadoDeRetorno);
setResult(RESULT_OK, intentRetorno);
finish();
Then make your own Activitya implement the method onActivityResult()
.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if(resultCode == RESULT_OK){
String result = data.getStringExtra("resultado");
}
}
}
Activity B will not leave the screen?
– Thiago Silva
yes a B is a form after I fill it I saved, I give a Finish() and send a data (just to confirm that it was saved) back to Activity A, this should always be open.
– daniel12345smith
You can create a method in Activitya and call the method created by Activityb.
– Eduardo Binotto