square/flow

Starting another activity (flow)

JurajBegovac opened this issue · 4 comments

Hi, I wasn't sure where to put this discussion because this is not an issue with library (I'll move this to stackoverflow or somewhere else if it's not suitable to have it here).

We're using Flow library in production and it's working very nice but I have some doubts and questions.
We treat one Activity as one Flow (so we have AccountAuthenticatorFlow, Feature1Flow etc.).
Each flow contains multiple screens (e.g. AccountAuthenticatorFlow contains LoginScreen, SignUpScreen, ForgotPassScreen etc.).

We've created this method in our abstract FlowActivity:

 protected void startAnotherFlow(TraversalCallback callback) {
    callback.onTraversalCompleted();
    Builder historyBuilder = Flow.get(this).getHistory().buildUpon();
    historyBuilder.pop();
    Flow.get(this).setHistory(historyBuilder.build(), REPLACE);
    startActivity(...); // start another activity/flow
  }

We call this method when there is key to start another flow in our KeyChanger from changeKey(...) method (each flow contains it's own KeyChanger).
In this method we pop last key from history because the last key on history starts another flow and we don't want to start another flow when we come back from another flow.

This is working okay, but I wonder if this is the best way to do this.
Is it okay to change history from changeKey(...) in KeyChanger (this is equal as changing history from dispatch(...) in Dispatcher)?

Changing history in changeKey queues up a key change which will run after the current one is complete.

Yep, it's fine. We need better redirect/reduction support (#191) but in the meantime, changing history from within changeKey is fine.

@loganj you probably meant #191 and most likely not #121

@Zhuinden thanks, edited