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.
精彩评论