title: java.lang.IllegalStateException activity with viewPager and tabs
body: <p>When I go back from the next activity, always savedInstanceState is null and when I rotate screen or turn back , I get this error:
  java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  I have tried to use in MyFragment
  View fragment = (View) inflater.inflate(R.layout.recycler_view, null);
  Or
  View fragment = (View) inflater.inflate(R.layout.recycler_view, container, false);
  or
  View fragment = (View) inflater.inflate(R.layout.recycler_view, container);
  but i get the same error.</p>
  
  <p>Error log:</p>
  
  <pre><code>java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
                                                                                  at android.view.ViewGroup.addViewInner(ViewGroup.java:3562)
                                                                                  at android.view.ViewGroup.addView(ViewGroup.java:3415)
                                                                                  at android.support.v4.view.ViewPager.addView(ViewPager.java:1342)
                                                                                  at android.view.ViewGroup.addView(ViewGroup.java:3360)
                                                                                  at android.view.ViewGroup.addView(ViewGroup.java:3336)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1094)
                                                                                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1259)
                                                                                  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                                  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1624)
                                                                                  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                                                  at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
                                                                                  at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
                                                                                  at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
                                                                                  at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:447)
                                                                                  ....
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>        public class MainActivity extends AppCompatActivity {
              static public DrawerLayout mDrawerLayout;
              private ArrayList&lt;ArrayList&lt;Article&gt;&gt; articlesHomeList;
  
  @Override
      public void onSaveInstanceState(Bundle savedInstanceState) {
          super.onSaveInstanceState(savedInstanceState);
          Log.d("--MainActivity", "onSaveInstanceState");
          // Save the user's current game state
          savedInstanceState.putSerializable("articlesHomeList", articlesHomeList);
          savedInstanceState.putString("test", "teststetststs");
          // Always call the superclass so it can save the view hierarchy state
      }
  
      @Override
      public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
          Log.d("--MainActivity", "onRestoreInstanceState");
          super.onRestoreInstanceState(savedInstanceState, persistentState);
          this.articlesHomeList = (ArrayList&lt;ArrayList&lt;Article&gt;&gt;) savedInstanceState.getSerializable("articlesHomeList");
      }
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
  
                  setContentView(R.layout.activity_main);
                  Bundle bundle = getIntent().getExtras();
                  articlesHomeList = (ArrayList&lt;ArrayList&lt;Article&gt;&gt;) bundle.getSerializable("articlesHomeList");
                  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
                  toolbar.setTitle(R.string.app_name);
                  setSupportActionBar(toolbar);
  
  
                  // Setting ViewPager for each Tabs
                  ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
                  setupViewPager(viewPager);
                  // Set Tabs inside Toolbar
                  TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
  
                  tabs.setupWithViewPager(viewPager);
  
  
                      }
  
              private void setupViewPager(ViewPager viewPager) {
  
                  Bundle bundleAll = new Bundle();
                  bundleAll.putSerializable("articles", (Serializable) this.articlesHomeList.get(2));
                  myFragment MyFragment = new MyFragment();
                  myFragment.setArguments(bundleAll);
  
                  AdapterTabs adapter = new AdapterTabs(getSupportFragmentManager());
                  adapter.addFragment(myFragment, "All");
  
                  viewPager.setAdapter(adapter);
                  viewPager.setCurrentItem(0);
              }
      @Override
          public boolean onOptionsItemSelected(MenuItem item) {
              // Handle action bar item clicks here. The action bar will
              // automatically handle clicks on the Home/Up button, so long
              // as you specify a parent activity in AndroidManifest.xml.
              int id = item.getItemId();
              Log.e("Item selected", Integer.toString(id));
              //noinspection SimplifiableIfStatement
              if (id == R.id.action_settings) {
                  return true;
              } else if (id == android.R.id.home) {
                  mDrawerLayout.openDrawer(GravityCompat.START);
              }
              return super.onOptionsItemSelected(item);
          }
  </code></pre>
  
  <p>myFragment:</p>
  
  <pre><code>    public class MyFragment extends Fragment {
          ...
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                   Bundle savedInstanceState) {
              View fragment = (View) inflater.inflate(R.layout.recycler_view, container, false);
              recyclerView = (RecyclerView) fragment.findViewById(R.id.my_recycler_view);
              articlesList = (List&lt;Article&gt;) this.getArguments().getSerializable("articles");
  
              ContentAdapter adapter = new ContentAdapter(articlesList);
              recyclerView.setAdapter(adapter);
              recyclerView.setHasFixedSize(true);
  
              recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
              return recyclerView;
          }
  ...
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have added to MainActivity:</p>
  
  <pre><code>if (savedInstanceState != null) {
              this.articlesHomeList = (ArrayList&lt;ArrayList&lt;Article&gt;&gt;) savedInstanceState.getSerializable("articlesHomeList");
              this.renderTabs(viewPager);
          } else if (getIntent().getExtras() != null) {
              Bundle bundle = getIntent().getExtras();
              articlesHomeList = (ArrayList&lt;ArrayList&lt;Article&gt;&gt;) bundle.getSerializable("articlesHomeList");
              this.renderTabs(viewPager);
          } else {
              this.loadArticlesHome(viewPager);
          }
  </code></pre>
  
  <p>But always savedInstanceState is null.</p>