2013-10-01 12 views
5

Ich habe eine Aktivität des Typs FragmentActivity. Im Inneren Ich habe einige Inhalte Ansicht Pager, wobei jedes scrollbaren Tab ein Fragment ist:Fragment Aktivität wird zerstört, wenn neue Aktivität von Fragment und gehen zurück

<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> 

Im Inneren des Fragments eine neue Aktivität Ich öffne, wenn der Benutzer auf den Eintrag in der Liste wie folgt tippt:

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

Aber wenn ich zurück in die InstaceActivity klicke, um zu dem mit Fragmenten zurückzukehren, wird es zerstört und neu erstellt. Ich habe keine Ahnung, warum das passiert. Sollte ich etwas Besonderes tun, um die FragmentActivity im Backstack zu halten?

Es hilft nicht einmal mit dem Zustand zu speichern:

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

Denn im oncreate Ereignisse des FragmentActivity der savedInstanceState NULL ist, wenn ich wieder drücken ??

Antwort

0

Versuchen Sie dies: addToBackStack. ;)

+0

Von dem, was ich verstehe, wird das verwendet, wenn von Fragment zu einem anderen Fragment, aber hier gehe ich von Fragment zu Aktivität. – andy57

+0

Oh ... Ich verstehe. Hast du das versucht und es hat nicht funktioniert? – nhgrif

+0

Ich ändere hier keine Fragmente und ich kann addToBackStack nur für FragmentTransaction verwenden. Ich habe es trotzdem versucht, aber es hat nichts geändert. – andy57

Verwandte Themen