I have a flow of activities that goes like this:
ProductA
> CreditCardA
> PaymentA
> ConfirmationA
> DoneA
Now, the confirmation screen needs information from ProductA
, CreditCardA
and PaymentA
. However, I don't want to keep passing data that is useless for the previous activities. The CreditCardA
needs to know nothing about the product, and PaymentA
doesn't really care about credit cards or the product itself, only about the price and in how many months this price can be paid.
So I thought about using GreenRobot EventBus. From ProductA
, a PaymentFlowA
would be called (with no layout), which would register in the EventBus and receive from it data related to the payment flow.
Something like this:
public class PaymentFlowActivity extends BaseActivity {
private CreditCard cc;
// etc...
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(CreditCardA);
}
@Override
protected void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
protected void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
@Subscribe
void onCreditCard(CreditCardMessage ccMsg;) {
cc = ccMsg.getCreditCard();
startActivity(PaymentA);
}
// etc...
}
Now, I'm afraid about activity shutdown. What happens if PaymentFlowA
is destroyed to free memory while the user is on, say, PaymentA
or ConfirmationA
? I'm afraid the instance state won't be restored properly.
Any thoughts?