diff --git a/sample/src/main/java/com/example/flow/MainActivity.java b/sample/src/main/java/com/example/flow/MainActivity.java index 647adf0..407767b 100644 --- a/sample/src/main/java/com/example/flow/MainActivity.java +++ b/sample/src/main/java/com/example/flow/MainActivity.java @@ -24,6 +24,8 @@ import static android.view.MenuItem.SHOW_AS_ACTION_ALWAYS; public class MainActivity extends Activity implements Flow.Listener { + private static final String BUNDLE_BACKSTACK = "backstack"; + @InjectView(R.id.container) FrameLayout containerView; private MenuItem friendsMenu; @@ -41,13 +43,18 @@ protected void onCreate(Bundle savedInstanceState) { final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowHomeEnabled(false); - flow = new Flow(Backstack.single(new App.ConversationList()), this); + flow = new Flow(getInitialBackstack(savedInstanceState), this); activityGraph = ObjectGraph.create(new ActivityModule()); - invalidateOptionsMenu(); go(flow.getBackstack(), Flow.Direction.FORWARD); } + @Override protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + outState.putParcelable(BUNDLE_BACKSTACK, flow.getBackstack()); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { friendsMenu = menu.add("Friends") .setShowAsActionFlags(SHOW_AS_ACTION_ALWAYS) @@ -89,6 +96,14 @@ protected void onCreate(Bundle savedInstanceState) { friendsMenu.setVisible(!hasUp); } + private Backstack getInitialBackstack(Bundle savedInstanceState) { + if (savedInstanceState != null) { + return savedInstanceState.getParcelable(BUNDLE_BACKSTACK); + } else { + return Backstack.single(new App.FriendList()); + } + } + private View getView(Screen screen) { ObjectGraph graph = activityGraph.plus(screen); Context scopedContext = new ScopedContext(this, graph);