开发者

Android startActivityForResult and child activity starts another activity

开发者 https://www.devze.com 2023-03-11 06:54 出处:网络
I have a scenario where I have my home screen (ActivityA) starting a login screen (ActivityB). This login screen will have a button to allow non-registered users to register an account, triggering (Ac

I have a scenario where I have my home screen (ActivityA) starting a login screen (ActivityB). This login screen will have a button to allow non-registered users to register an account, triggering (ActivityC).

In my code, I am having ActivityA

public class ActivityA extends Activity {
  ...
  startActivityForResult(new Intent(this, ActivityB.class), 0);
  ...
}

and ActivityB

public class ActivityB extends Activity {
 ...
 startActivity(new Intent(this, ActivityC.class));
 ...
}

Well it seems to work, but I'm concerned if there is any hidden problem that can possibly return to haunt me later? In ActivityB, if I start ActivityC, there is no setResult() call to trigger onActivityResult() of ActivityA. Is there any issue with such a flow, or should I be using startActivity instead of startActivit开发者_如何学JAVAyForResult?


ActivtyA's onActivityResult method will be triggered by ActivityB when it finishes. It doesn't matter what ActivityB does during its lifecycle or how many new Activities it spawns, when finish() is called on ActivityB (hopefully after calling setResult() it will propagate back to ActivityA. The only gap in your communication is that ActivityC can't tell ActivityB anything when it finishes. If you don't need that, you're fine; A and B's communication is still unaltered.

0

精彩评论

暂无评论...
验证码 换一张
取 消