Avoid recreating same view when perform tab switching
<p>Current, I have 2 <code>Fragments</code>, which is switch-able through <code>ActionBar</code>'s tab.</p>

<pre><code>    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab newTab = getSupportActionBar().newTab();
    newTab.setText("history");
    newTab.setTabListener(new TabListenerHistoryFragment&gt;(this, "history",
        HistoryFragment.class));
</code></pre>

<hr>

<pre><code> @Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // Check if the fragment is already initialized
    if (mFragment == null) {

        // If not, instantiate and add it to the activity
        mFragment = Fragment.instantiate(mActivity, mClass.getName());
        mFragment.setRetainInstance(true);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        // If it exists, simply attach it in order to show it
        ft.attach(mFragment);
    }        
}
</code></pre>

<p>I realize the first time of my <code>Activity</code> (This activity is holding 2 fragments) being launched, <code>Fragment</code>s' methods will be called in the following sequence.</p>

<p><code>onCreate -&gt; onCreateView -&gt; onStart</code></p>

<p>When I perform Tab switching, and then Tab switching back to the same Fragment, the following methods will be called again.</p>

<p><code>onCreateView -&gt; onStart</code></p>

<p>I just wish to retain the same GUI view state, when Tab is being switched back.</p>

<ul>
<li>I want my chart continue to be zoomed into previous level.</li>
<li>I want my chart horizontal scroll stay at previous level.</li>
<li>I want my list continue scroll stay at previous level.</li>
<li>...</li>
</ul>

<p>I know that I can save/restore simple variables using the following method when Tab switching</p>

<p><a href="http://stackoverflow.com/questions/6787071/android-fragment-how-to-save-states-of-views-in-a-fragment-when-another-fragmen">android fragment- How to save states of views in a fragment when another fragment is pushed on top of it</a></p>

<p>But, that is not something I want, as my GUI state is pretty difficult to describe within whole bunch of primitive values.</p>

<p>I try the following approach. Of course it won't work, as I am getting the following runtime error.</p>

<pre><code>public class HistoryFragment extends Fragment {
    View view = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (this.view != null) {
            return this.view;
        }
        this.view = inflater.inflate(R.layout.history_activity, container, false); 
    }
}
</code></pre>

<p><strong>java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</strong></p>

<p>I realize the following demo example is able to preserve its fragment GUI state (For instance, the position of vertical scroll of list) when there is Tab switching. But I guess, perhaps it is because they are using ListFragment? As I do not find they perform any special handling to preserve GUI state.</p>

<ul>
<li>com.example.android.apis.app.FragmentTabs</li>
<li>com.example.android.apis.app.LoaderCursor.CursorLoaderListFragment</li>
</ul>

<p><strong>May I know, how I can avoid from recreating same view when perform tab switching？</strong></p>
