IndexOutOfBoundsException when restoring navigation tab state
<p>I'm using action bar tab navigation and when I rotate screen I get IndexOutOfBoundsException</p>

<p>According to logcat problem is in <code>getSupportActionBar().setSelectedNavigationItem(
                    savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));</code></p>

<pre><code>@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Restore the previously serialized current tab position.
    if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
        getSupportActionBar().setSelectedNavigationItem(
                savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
    }
}

@Override
public void onSaveInstanceState(Bundle outState) {
    // Serialize the current tab position.
    outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getSupportActionBar()
            .getSelectedNavigationIndex());
}
</code></pre>

<p><strong>EDIT</strong><br>
I found the problem. I use AsyncTask to gather all info that will be showed in tabs and I add tabs in <code>onPostExecute</code>.  </p>

<p><code>onRestoreInstanceState</code> is called before <code>onPostExecute</code> so the tab count is still 0.</p>
