Java Code Examples for android.support.v4.app.fragment#setRetainInstance()
The following examples show how to use
android.support.v4.app.fragment#setRetainInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacebookActivity.java From letv with Apache License 2.0 | 6 votes |
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.com_facebook_activity_layout); Intent intent = getIntent(); if (PASS_THROUGH_CANCEL_ACTION.equals(intent.getAction())) { handlePassThroughError(); return; } FragmentManager manager = getSupportFragmentManager(); Fragment fragment = manager.findFragmentByTag(FRAGMENT_TAG); if (fragment == null) { if (FacebookDialogFragment.TAG.equals(intent.getAction())) { Fragment dialogFragment = new FacebookDialogFragment(); dialogFragment.setRetainInstance(true); dialogFragment.show(manager, FRAGMENT_TAG); fragment = dialogFragment; } else { fragment = new LoginFragment(); fragment.setRetainInstance(true); manager.beginTransaction().add(R.id.com_facebook_fragment_container, fragment, FRAGMENT_TAG).commit(); } } this.singleFragment = fragment; }
Example 2
Source File: FragmentLifecycleCallbacksImpl.java From lifecycle-component with Apache License 2.0 | 5 votes |
@Override public void onFragmentCreated(FragmentManager fm, Fragment f, Bundle savedInstanceState) { Timber.i(f.toString() + " - onFragmentCreated"); // 在配置变化的时候将这个 Fragment 保存下来,在 Activity 由于配置变化重建时重复利用已经创建的 Fragment。 // https://developer.android.com/reference/android/app/Fragment.html?hl=zh-cn#setRetainInstance(boolean) // 如果在 XML 中使用 <Fragment/> 标签,的方式创建 Fragment 请务必在标签中加上 android:id 或者 android:tag 属性,否则 setRetainInstance(true) 无效 // 在 Activity 中绑定少量的 Fragment 建议这样做,如果需要绑定较多的 Fragment 不建议设置此参数,如 ViewPager 需要展示较多 Fragment f.setRetainInstance(true); }
Example 3
Source File: FacebookActivity.java From kognitivo with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.com_facebook_activity_layout); Intent intent = getIntent(); if (PASS_THROUGH_CANCEL_ACTION.equals(intent.getAction())) { handlePassThroughError(); return; } FragmentManager manager = getSupportFragmentManager(); Fragment fragment = manager.findFragmentByTag(FRAGMENT_TAG); if (fragment == null) { if (FacebookDialogFragment.TAG.equals(intent.getAction())) { FacebookDialogFragment dialogFragment = new FacebookDialogFragment(); dialogFragment.setRetainInstance(true); dialogFragment.show(manager, FRAGMENT_TAG); fragment = dialogFragment; } else { fragment = new LoginFragment(); fragment.setRetainInstance(true); manager.beginTransaction() .add(R.id.com_facebook_fragment_container, fragment, FRAGMENT_TAG) .commit(); } } singleFragment = fragment; }
Example 4
Source File: SidebarAdapter.java From VCL-Android with Apache License 2.0 | 5 votes |
public Fragment fetchFragment(String id) { // Save the previous fragment in case an error happens after. String prevFragmentId = mCurrentFragmentId; // Set the current fragment. setCurrentFragment(id); if(mFragments.containsKey(id) && mFragments.get(id) != null) { return mFragments.get(id); } Fragment f; if(id.equals(SidebarEntry.ID_AUDIO)) { f = new AudioBrowserFragment(); } else if(id.equals(SidebarEntry.ID_VIDEO)) { f = new VideoGridFragment(); } else if(id.endsWith(SidebarEntry.ID_DIRECTORIES)) { f = new FileBrowserFragment(); } else if(id.equals(SidebarEntry.ID_HISTORY)) { f = new HistoryFragment(); } else if(id.equals(SidebarEntry.ID_MRL)) { f = new MRLPanelFragment(); } else if(id.equals(SidebarEntry.ID_NETWORK)) { f = new NetworkBrowserFragment(); } else { mCurrentFragmentId = prevFragmentId; // Restore the current fragment id. throw new IllegalArgumentException("Wrong fragment id."); } f.setRetainInstance(true); mFragments.put(id, f); return f; }