7

I have an activity of type FragmentActivity. Inside I have some content using view pager, where each scrollable tab is a fragment:

<android.support.v4.view.ViewPager      
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OpenStack" >

    <!--
    This title strip will display the currently visible page title, as well as the page
    titles for adjacent pages.
    -->

    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#33b5e5"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" />

</android.support.v4.view.ViewPager>

Inside the fragment I'm opening a new activity when user taps on the item in the list like this:

Intent myIntent = new Intent(getActivity(), InstanceActivity.class);
getActivity().startActivity(myIntent);

But when i click back in the InstaceActivity to return to the one with fragments it is destroyed and created again. I have to no idea why that happens. Should I do something special to keep the FragmentActivity in the backstack?

It doesn't even help to save the state with:

public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString("CONNTOKEN", isConnToken);
    outState.putString("NOVAURL", isNovaURL);
}   

Because in the oncreate event of the FragmentActivity the savedInstanceState is NULL when I press back ??

andy57
  • 123
  • 4

1 Answers1

0

Try this: addToBackStack. ;)

nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • From what I understand, that is used when going from fragment to another fragment, but here i'm going from fragment to activity. – andy57 Oct 01 '13 at 21:14
  • I'm not changing fragments here and I can only use addToBackStack on FragmentTransaction. I tried that anyway, but it didn't change anything. – andy57 Oct 01 '13 at 21:23