Fragment setRetainInstance - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Fragment setRetainInstance method.

This code example shows how to use the following methods:setRetainInstance
	 
	public ColorFragment() {  
		this(R.color.white);
	} 
	 
	public ColorFragment(int colorRes) {
		mColorRes = colorRes;
		setRetainInstance(true);
	} 
 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if (savedInstanceState != null)
			mColorRes = savedInstanceState.getInt("mColorRes");
		int color = getResources().getColor(mColorRes);
		// construct the RelativeLayout 
		RelativeLayout v = new RelativeLayout(getActivity());
		v.setBackgroundColor(color);		
		return v;
	} 
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
  public ContentFragment() { 
    this(null); 
  } 
   
  public ContentFragment(String url) {
    super(); 
     
    urlToLoad=url;
    setRetainInstance(true);
  } 
   
  @Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
    return(inflater.inflate(R.layout.content_fragment, container, false));
  } 
   
  @Override 
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
10
CodeRank
This code example shows how to use the following methods:setRetainInstance, setUserVisibleHint
public class SupportSelectionStateFragment extends Fragment implements SelectionState {
 
  private CommonSelectionStateFragment _common = new CommonSelectionStateFragment();
 
  public SupportSelectionStateFragment() { 
    super(); 
    setRetainInstance(true);
    setUserVisibleHint(false);
  } 
 
  @Override 
  public void onSaveInstanceState(final Bundle state) {
    super.onSaveInstanceState(state);
    _common.onSaveInstanceState(state);
  } 
 
  @Override 
  public void onCreate(final Bundle state) {
    super.onCreate(state);
    _common.onCreate(state);
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
import android.view.ViewGroup; 
import android.widget.TextView; 
 
public class NewFragment extends Fragment {
 
	public NewFragment(){ 
		setRetainInstance(true);
	} 
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_page_layout, null);
		TextView textView = (TextView)view.findViewById(R.id.tv_text);
		textView.setText("This is a new fragment");
		return view;
	} 
 
	@Override 
	public void onCreate(Bundle savedInstanceState) {
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
	 
	public ColorFragment() {  
		this(R.color.white);
	} 
	 
	public ColorFragment(int colorRes) {
		mColorRes = colorRes;
		setRetainInstance(true);
	} 
 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		if (savedInstanceState != null)
			mColorRes = savedInstanceState.getInt("mColorRes");
		int color = getResources().getColor(mColorRes);
		// construct the RelativeLayout 
		RelativeLayout v = new RelativeLayout(getActivity());
		v.setBackgroundColor(color);		
		return v;
	} 
10
CodeRank
This code example shows how to use the following methods:getActivity, onActivityCreated, setRetainInstance
    return(result);
  } 
 
  @Override 
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
 
    setRetainInstance(true);
    getActivity().getApplicationContext()
                 .bindService(new Intent(
                                         "com.commonsware.android.advservice.IScript"), 
                              this, Context.BIND_AUTO_CREATE);
  } 
 
  @Override 
  public void onDestroy() { 
    getActivity().getApplicationContext().unbindService(this);
 
    super.onDestroy(); 
  } 
8
CodeRank
This code example shows how to use the following methods:setRetainInstance
 * @author Ryan 
 * 
 */ 
public class MainPageFragment extends Fragment{
 
	public MainPageFragment(){ 
		setRetainInstance(true);
	} 
	 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.main_page_layout, null);
	     
		return view;
	} 
 
	@Override 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
10
CodeRank
This code example shows how to use the following methods:setRetainInstance
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
/** 
 * 滑动菜单 
 * @author Ryan 
 */ 
public class MenuFragment extends ListFragment {
 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		ListView listView = (ListView)inflater.inflate(R.layout.list_fragment, null);
		listView.setCacheColorHint(0);
		return listView;
	} 
 
	@Override 
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		//右侧隐藏菜单 
		String[] colors = new String[]{"Main","Fragment","Activity"};
10
CodeRank
This code example shows how to use the following methods:onCreate, setRetainInstance
 
   public ImageCacheFragment(){} 
 
   @Override 
   public void onCreate(Bundle savedInstanceState){
      super.onCreate(savedInstanceState);
      setRetainInstance(true);
   } 
} 
7
CodeRank
This code example shows how to use the following methods:setRetainInstance
import android.view.View; 
import android.view.ViewGroup; 
 
public class mainFragment extends Fragment{
	 
	public mainFragment() { 
			setRetainInstance(true);
	} 
 
	@Override 
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		 
		// construct the RelativeLayout 
		View v = new View(getActivity());
		v = inflater.inflate(R.layout.activity_main, null);		
		return v;
	}	 
} 
10
CodeRank

Related Fragment setRetainInstance Questions & Answers:

setRetainInstance Method Overview
Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change).
See Code Examples for other Android Fragment Methods: