title: Save state of dynamic ViewPager
body: <p>I have an android app in which I want to dynamically add and remove Fragments to a ViewPager during runtime, and preserving the Fragments on configuration changes.</p>
  
  <p>Thus far I have implemented a FragmentStatePagerAdapter, holding my Fragments in a list with methods <code>add</code>, <code>remove</code> and <code>replace</code> to manipulate my Fragments. Basically, all they do is insert or delete a Fragment in the list and then call <code>notifyDatasetChanged()</code>. I insert the staring Fragment as a new Fragment during the Activitys <code>onCreate()</code> method.</p>
  
  <p>I know want to preserve my Fragments during configuration changes. Currently, when I change my screen orientation, all my currently Fragments are deleted, and I get back to the starting Fragment, naturally because the Activity is recreated, and the Fragment and the Adapater are reinstantiated during the <code>onCreate()</code> call. I was trying to save the state of the Adapter with the <code>Adapter.saveInstance()</code> during the Activitys <code>onPause()</code>, but when I try to restore it via <code>Adapter.restoreInstance()</code>, I get an empty adapter.</p>
  
  <p>Can anyone give me a hint on what is the correct way in Android to save state a <code>FragmentStatePagerAdapter</code>?</p>