title: Save state on NavigationView
body: <p>I'm working with the new <a href="https://developer.android.com/reference/android/support/design/widget/NavigationView.html" rel="nofollow">NavigationView</a>, trying to implement it into a <a href="https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html" rel="nofollow">DrawerLayout</a>, and I want to save the currently selected menu item in the menu within the NavigationView.
  I know that I can save/restore the selected item "manually" by saving/restoring my instance state:</p>
  
  <pre><code>public class MyActivity extends AppCompatActivity {
      private static String STATE_SELECTED_POSITION = "state_selected_position";
      private int mCurrentSelectedPosition;
  
      private NavigationView mNavigationView;
      private FrameLayout mContentFrame;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
          mContentFrame = (FrameLayout) findViewById(R.id.content_frame);
  
          mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
              @Override
              public boolean onNavigationItemSelected(MenuItem menuItem) {
                  menuItem.setChecked(true);
  
                  switch(menuItem.getItemId()) {
                      case R.id.navigation_item_1:
                          Snackbar.make(contentFrame, "Item One", Snackbar.LENGTH_SHORT).show();
                          mCurrentSelectedPosition = 0;
                          return true;
                      case R.id.navigation_item_2:
                          Snackbar.make(contentFrame, "Item Two", Snackbar.LENGTH_SHORT).show();
                          mCurrentSelectedPosition = 1;
                          return true;
                      default:
                          return false;
                  }
              }
          });
      }
  
      // Saving the currently selected menu item (index).
      public void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
      }
  
      // Restoring selected menu item.
      protected void onRestoreInstanceState(Bundle savedInstanceState) {
          super.onRestoreInstanceState(savedInstanceState);
  
          mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION, 0);
          mNavigationView.getMenu().getItem(mCurrentSelectedPosition).setChecked(true);
      }
  
  }
  </code></pre>
  
  <p>I stumbled upon the <a href="https://developer.android.com/reference/android/support/design/widget/NavigationView.SavedState.html" rel="nofollow">NavigationView.SavedState</a>, hoping this would be a better solution, but I'm having trouble figuring out how to implement this into my activity.
  Anyone who can help me figure out how to implement this? Thanks.</p>