Slide 31
Slide 31 text
Step-by-step handling view navigation
(Simple-Stack)
@BindView(R.id.root)
RelativeLayout root;
@Override
public void handleStateChange(StateChange stateChange,
Callback completionCallback) {
if(stateChange.topNewState().equals(stateChange.topPreviousState())) {
completionCallback.stateChangeComplete();
return;
}
backstackDelegate.persistViewToState(root.getChildAt(0));
root.removeAllViews();
Key newKey = stateChange.topNewState();
Context newContext = stateChange.createContext(this, newKey);
View view = LayoutInflater.from(newContext)
.inflate(newKey.layout(), root, false);
backstackDelegate.restoreViewFromState(view);
root.addView(view);
completionCallback.stateChangeComplete();
}
// + lifecycle integration callbacks!
( onCreate(), onPostResume(), onPause(),
onRetainCustomNonConfigurationInstance(), onDestroy() )