Shutdown onActivityResult not working

I have a couple of actions that must live or die together. Basically, AlphaActivity does some work and then sends the intent ( startActivityForResult() ) to BetaActivity. When BetaActivity is complete, I want it to send an intention ( startActivity() ) for GammaActivity, and then I call finish() . At the end, I was hoping that the AlphaActivity onActivityResult() method would be called, but that didn't seem to happen. My design is such that inside AlphaActivity onActivityResult() I call finish() . My plan is that after reaching GammaActivity, the user can never return to either AlphaActivity or BetaActivity. But currently, the back button brings the user to AlphaActivity.

I have some ideas why this does not work, but discussing them here is pointless, as I am interested in what might actually work.

EDIT:

The code is all pretty standard stuff:

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(); } } } 

Inside Beta:

 if (success) { startGammaActivity(); finish(); } 
+4
android android-intent android-activity activity-finish back
source share
3 answers

I think you just need to:

 if (success) { startGammaActivity(); setResult(Activity.RESULT_OK); //add this finish(); } 
+6
source share

In my perspective you should follow this,

  • AlphaActivity launches BetaActivity for result with query code X
  • BetaActivity does its job and then calls setResult (Y, Z) and ends the call ()
  • AlphaActivity will run onActivityResult with RequestCode X, ResultCode Y and data Z. If X and Y are the ones you expect, then start GammaActivity and finally end the call () in AlphaActivity

You should not run GammaActivity in BetaActivity because AlphaActivity onActivityResult will not work properly.

+4
source share

You did not call setResult ()

 if (success) { startGammaActivity(); setResult(RESULT_OK); finish(); } 

Or, if you do not need to return from BetaActivity to AlphaActivity , then in both actions the manifest puts android:noHistory=true

+4
source share

All Articles