Best code examples for Fragment setRetainInstance method (android.app.Fragment.setRetainInstance)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Fragment setRetainInstance method.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Fragment setRetainInstance examples from Open Source projects
This code example shows how to use the following methods: setRetainInstance
20:	public ColorFragment(int colorRes) { 
-
22:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
33:	super(); 
-
36:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance, setUserVisibleHint
15:	super(); 
16:	setRetainInstance(true); 
17:	setUserVisibleHint(false); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
12:	public NewFragment(){ 
13:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
19:	public ColorFragment(int colorRes) { 
-
21:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: getActivity, onActivityCreated, setRetainInstance
39:	super.onActivityCreated(savedInstanceState); 
-
41:	setRetainInstance(true); 
42:	getActivity().getApplicationContext() 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setRetainInstance
15:	public MainPageFragment(){ 
16:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
15:	*/ 
16:	public class MenuFragment extends ListFragment { 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: onCreate, setRetainInstance
30:	super.onCreate(savedInstanceState); 
31:	setRetainInstance(true); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRetainInstance
13:	public mainFragment() { 
14:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: getArguments, onCreate, setRetainInstance
41:	super.onCreate(savedInstanceState); 
42:	setRetainInstance(true); 
43:	Bundle b = getArguments(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setRetainInstance
14:	public DefaultFragment() { 
15:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
14:	public NewFragment(){ 
15:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: onCreate, setRetainInstance
35:	super.onCreate(savedInstanceState); 
36:	setRetainInstance(true); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: onCreate, setRetainInstance
37:	super.onCreate(savedInstanceState); 
38:	setRetainInstance(true); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setRetainInstance
33:	public RideListStateFragment() { 
34:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
18:	public ColorFragment(int colorRes) { 
-
20:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: onCreate, setRetainInstance
15:	super.onCreate(savedInstanceState); 
16:	setRetainInstance(true); 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: setRetainInstance
18:	public ColorFragment(int colorRes) { 
-
20:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
20:	public ColorFragment(int colorRes) { 
-
22:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
20:	public ColorFragment(int colorRes) { 
-
22:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
13:	public StatsSummaryFragment() { 
14:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
17:	public MainPageFragment(){ 
18:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
33:	public SearchFragment() { 
34:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
40:	public SleeveFragment(String title, int channel) { 
-
43:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setRetainInstance
19:	public ReportSimpleFragment() { 
20:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: setArguments, setRetainInstance
15:	f.setArguments(args); 
16:	f.setRetainInstance(true); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: setRetainInstance
33:	super(); 
-
36:	setRetainInstance(true); 
Full Snippet Info
10
CodeRank
This code example shows how to use the following methods: onAttach, setRetainInstance
53:	super.onAttach(activity); 
54:	setRetainInstance(true); 
Full Snippet Info
5
CodeRank
This code example shows how to use the following methods: setRetainInstance
35:	public RoomFragment() { 
36:	setRetainInstance(true); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setRetainInstance
199:	public MyFragment() { 
-
201:	setRetainInstance(true); // this will prevent the app from crashing on screen rotation 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setRetainInstance
138:	Fragment f = new Fragment(); 
-
140:	f.setRetainInstance(true); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: setRetainInstance
382:	public SearchResultsFragment() 
-
384:	setRetainInstance(true); 
Full Snippet Info
9
CodeRank
Related Fragment setRetainInstance Questions & Answers:
A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity. Interaction with fragments is done through FragmentManager, which can be obtained via Activity.getFragmentManager() and Fragment.getFragmentManager().

The Fragment class can be used many ways to achieve a wide variety of results. In its core, it represents a particular operation or interface that is running within a larger Activity. A Fragment is closely tied to the Activity it is in, and can not be used apart from one. Though Fragment defines its own lifecycle, that lifecycle is dependent on its activity: if the activity is stopped, no fragments inside of it can be started; when the activity is destroyed, all fragments will be destroyed. All subclasses of Fragment must include a public empty constructor. The framework will often re-instantiate a fragment class when needed, in particular during state restore, and needs to be able to find this constructor to instantiate it. If the empty constructor is not available, a runtime exception will occur in some cases during state restore. Topics covered here: Older Platforms Lifecycle Layout Back Stack Developer Guides For more information about using fragments, read the Fragments developer guide. Older Platforms While the Fragment API was introduced in HONEYCOMB, a version of the API at is also available for use on older platforms through FragmentActivity. See the blog post Fragments For All for more details. Lifecycle Though a Fragment's lifecycle is tied to its owning activity, it has its own wrinkle on the standard activity lifecycle. It includes basic activity lifecycle methods such as onResume(), but also important are methods related to interactions with the activity and UI generation. The core series of lifecycle methods that are called to bring a fragment up to resumed state (interacting with the user) are: onAttach(Activity) called once the fragment is associated with its activity. onCreate(Bundle) called to do initial creation of the fragment. onCreateView(LayoutInflater, ViewGroup, Bundle) creates and returns the view hierarchy associated with the fragment. onActivityCreated(Bundle) tells the fragment that its activity has completed its own Activity.onCreate(). onViewStateRestored(Bundle) tells the fragment that all of the saved state of its view hierarchy has been restored. onStart() makes the fragment visible to the user (based on its containing activity being started). onResume() makes the fragment interacting with the user (based on its containing activity being resumed). As a fragment is no longer being used, it goes through a reverse series of callbacks: onPause() fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity. onStop() fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity. onDestroyView() allows the fragment to clean up resources associated with its View. onDestroy() called to do final cleanup of the fragment's state. onDetach() called immediately prior to the fragment no longer being associated with its activity. Layout Fragments can be used as part of your application's layout, allowing you to better modularize your code and more easily adjust your user interface to the screen it is running on. As an example, we can look at a simple program consisting of a list of items, and display of the details of each item.An activity's layout XML can include tags to embed fragment instances inside of the layout. For example, here is a simple layout that embeds one fragment:The layout is installed in the activity in the normal way:The titles fragment, showing a list of titles, is fairly simple, relying on ListFragment for most of its work. Note the implementation of clicking an item: depending on the current activity's layout, it can either create and display a new fragment to show the details in-place (more about this later), or start a new activity to show the details.The details fragment showing the contents of a selected item just displays a string of text based on an index of a string array built in to the app:In this case when the user clicks on a title, there is no details container in the current activity, so the titles fragment's click code will launch a new activity to display the details fragment:However the screen may be large enough to show both the list of titles and details about the currently selected title. To use such a layout on a landscape screen, this alternative layout can be placed under layout-land:Note how the prior code will adjust to this alternative UI flow: the titles fragment will now embed the details fragment inside of this activity, and the details activity will finish itself if it is running in a configuration where the details can be shown in-place. When a configuration change causes the activity hosting these fragments to restart, its new instance may use a different layout that doesn't include the same fragments as the previous layout. In this case all of the previous fragments will still be instantiated and running in the new instance. However, any that are no longer associated with a tag in the view hierarchy will not have their content view created and will return false from isInLayout(). (The code here also shows how you can determine if a fragment placed in a container is no longer running in a layout with that container and avoid creating its view hierarchy in that case.) The attributes of the tag are used to control the LayoutParams provided when attaching the fragment's view to the parent container. They can also be parsed by the fragment in onInflate(Activity, AttributeSet, Bundle) as parameters. The fragment being instantiated must have some kind of unique identifier so that it can be re-associated with a previous instance if the parent activity needs to be destroyed and recreated. This can be provided these ways: If nothing is explicitly supplied, the view ID of the container will be used. android:tag can be used in to provide a specific tag name for the fragment. android:id can be used in to provide a specific identifier for the fragment. Back Stack The transaction in which fragments are modified can be placed on an internal back-stack of the owning activity. When the user presses back in the activity, any transactions on the back stack are popped off before the activity itself is finished. For example, consider this simple fragment that is instantiated with an integer argument and displays that in a TextView in its UI:A function that creates a new instance of the fragment, replacing whatever current fragment instance is being shown and pushing that change on to the back stack could be written as: void addFragmentToStack() { mStackLevel++; // Instantiate a new fragment. Fragment newFragment = CountingFragment.newInstance(mStackLevel); // Add the fragment to the activity, pushing this transaction // on to the back stack. FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.simple_fragment, newFragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(null); ft.commit(); } After each call to this function, a new entry is on the stack, and pressing back will pop it to return t...
setRetainInstance Method Overview
Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change).
See Also
  • getActivity
    Return the Activity this fragment is currently associated with.
  • getArguments
    Return the arguments supplied when the fragment was instantiated, if any.
  • getChildFragmentManager
    Return a private FragmentManager for placing and managing Fragments inside of this Fragment.
  • getFragmentManager
    Return the FragmentManager for interacting with fragments associated with this fragment's activity.
  • getId
    Return the identifier this fragment is known by.
  • getLoaderManager
    Return the LoaderManager for this fragment, creating it if needed.
  • getString
    Return a localized string from the application's package's default string table.
  • getTag
    Get the tag name of the fragment, if specified.
  • getView
    Get the root view for the fragment's layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.
  • instantiate
    Like instantiate(Context, String, Bundle) but with a null argument Bundle.
  • isAdded
    Return true if the fragment is currently added to its activity.
  • isDetached
    Return true if the fragment has been explicitly detached from the UI.
  • isVisible
    Return true if the fragment is currently visible to the user.
  • onActivityCreated
    Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.
  • onActivityResult
    Receive the result from a previous call to startActivityForResult(Intent, int).
  • onAttach
    Called when a fragment is first attached to its activity.
  • onConfigurationChanged
    Called by the system when the device configuration changes while your component is running.
  • onCreate
    Called to do initial creation of a fragment.
  • onCreateView
    Called to have the fragment instantiate its user interface view.
  • onDestroy
    Called when the fragment is no longer in use.
  • onDestroyView
    Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment.
  • onDetach
    Called when the fragment is no longer attached to its activity.
  • onPause
    Called when the Fragment is no longer resumed.
  • onResume
    Called when the fragment is visible to the user and actively running.
  • onSaveInstanceState
    Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted.
  • onStart
    Called when the Fragment is visible to the user.
  • onStop
    Called when the Fragment is no longer started.
  • onViewCreated
    Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view.
  • setArguments
    Supply the construction arguments for this fragment.
  • setHasOptionsMenu
    Report that this fragment would like to participate in populating the options menu by receiving a call to onCreateOptionsMenu(Menu, MenuInflater) and related methods.
  • setUserVisibleHint
    Set a hint to the system about whether this fragment's UI is currently visible to the user.
  • startActivity
    Call startActivity(Intent) from the fragment's containing Activity.
  • toString
    Returns a string containing a concise, human-readable description of this object.