I have a pair of activities that must live or die together. Basically AlphaActivity does some work and then dispatches an intent (startActivityForResult()
) for BetaActivity. When BetaActivity is done, I want it to dispatch an intent (startActivity()
) for GammaActivity and then call finish()
on itself. Upon finishing I was hoping for AlphaActivity's onActivityResult()
method to be called, but that never seems to happen. My design is such that inside AlphaActivity's onActivityResult()
, I call finish()
. My plan is such that once GammaActivity is reached, a user cannot ever return to either AlphaActivity or BetaActivity. But presently the back button does take the user to the AlphaActivity.
I do have some ideas why it's not working, but discussing them here is pointless since I am interested in what might actually work.
EDIT:
The code is all quite standard stuff:
From inside Alpha
private void startBetaActivity() {
Intent intent = new Intent(this, BetaActivity.class);
startActivityForResult(intent, Constant.EXIT_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == Constant.EXIT_CODE) {
this.finish();
}
}
}
From inside Beta:
if (success) {
startGammaActivity();
finish();
}
I think you just need to:
if (success) {
startGammaActivity();
setResult(Activity.RESULT_OK); //add this
finish();
}
In my perspective you should follow this,
You should not start GammaActivity on BetaActivity because the AlphaActivity onActivityResult will not work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With