0

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?

  • You should use SharedPreferences. You will not be able to receive the data till the activity is created, at the best, and all of this seems to be too hack-ish. – user2520215 Oct 06 '17 at 15:08
  • @user2520215 Hm, I think I'll just pass the data horizontally : / SharedPreferences doesn't seem like a good idea... how would I retrieve the data in the ConfirmationA? –  Oct 06 '17 at 16:33

0 Answers0