Skip to content

Commit

Permalink
Prevent KeyManager from setting up services for a key on config change
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Amos committed Feb 21, 2016
1 parent 841f102 commit b321d1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 9 additions & 3 deletions flow/src/main/java/flow/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public static void addHistory(@NonNull Intent intent, @NonNull History history,
* not be affected.
*/
public void setDispatcher(@NonNull Dispatcher dispatcher) {
setDispatcher(dispatcher, false);
}

void setDispatcher(@NonNull Dispatcher dispatcher, final boolean restore) {
this.dispatcher = checkNotNull(dispatcher, "dispatcher");

if (pendingTraversal == null || //
Expand All @@ -122,7 +126,7 @@ public void setDispatcher(@NonNull Dispatcher dispatcher) {
// So enqueue a bootstrap traversal.
move(new PendingTraversal() {
@Override void doExecute() {
bootstrap(history);
bootstrap(history, restore);
}
});
return;
Expand Down Expand Up @@ -340,11 +344,13 @@ void enqueue(PendingTraversal pendingTraversal) {
}
}

void bootstrap(History history) {
void bootstrap(History history, boolean restore) {
if (dispatcher == null) {
throw new AssertionError("Bad doExecute method allowed dispatcher to be cleared");
}
keyManager.setUp(history.top());
if (!restore) {
keyManager.setUp(history.top());
}
dispatcher.dispatch(new Traversal(null, history, Direction.REPLACE, keyManager), this);
}

Expand Down
4 changes: 3 additions & 1 deletion flow/src/main/java/flow/InternalLifecycleIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ void onNewIntent(Intent intent) {
}
History history = selectHistory(intent, savedHistory, defaultHistory, parceler, keyManager);
flow = new Flow(keyManager, history);
flow.setDispatcher(dispatcher, false);
} else {
flow.setDispatcher(dispatcher, true);
}
flow.setDispatcher(dispatcher);
dispatcherSet = true;
}

Expand Down

0 comments on commit b321d1b

Please sign in to comment.