finish activity in onActivityResult does not work

倾然丶 夕夏残阳落幕 提交于 2019-12-04 09:05:39

I think you just need to:

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

In my perspective you should follow this,

  1. AlphaActivity starts BetaActivity for result with X request code
  2. BetaActivity does his work and then calls setResult(Y, Z) and call finish()
  3. AlphaActivity will run onActivityResult with RequestCode X, ResultCode Y and data Z. If X and Y are the ones that you are expecting then starts GammaActivity and finally call finish() on AlphaActivity

You should not start GammaActivity on BetaActivity because the AlphaActivity onActivityResult will not work properly.

Hoan Nguyen

You have not called setResult()

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

Or if you never need to go back from BetaActivity to AlphaActivity then in both activities manifest put android:noHistory=true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!