问题描述
我有两项必须共同生活或死亡的活动.基本上,AlphaActivity会做一些工作,然后为BetaActivity调度一个意图(startActivityForResult()
).完成BetaActivity后,我希望它为GammaActivity调度一个意图(startActivity()
),然后对其自身调用finish()
.完成后,我希望调用AlphaActivity的onActivityResult()
方法,但这似乎从未发生.我的设计是这样的:在AlphaActivity的onActivityResult()
中,我称为finish()
.我的计划是,一旦达到GammaActivity,用户将永远无法返回AlphaActivity或BetaActivity.但是目前,后退"按钮确实将用户带到AlphaActivity.
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.
代码都是非常标准的东西:
The code is all quite standard stuff:
从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();
}
}
}
在Beta内部:
if (success) {
startGammaActivity();
finish();
}
推荐答案
我认为您只需要:
if (success) {
startGammaActivity();
setResult(Activity.RESULT_OK); //add this
finish();
}
这篇关于onActivityResult中的完成活动不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!