List of usage examples for android.app FragmentTransaction commitAllowingStateLoss
public abstract int commitAllowingStateLoss();
From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java
private void showMirrorView(final FragmentManager fragmentManager, final MirrorView mirrorView, final boolean addToBackStack, final String tag) { if (mirrorView.isFullscreen()) { mFullscreenContainer.setVisibility(View.VISIBLE); final FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(getContainerViewId(), (Fragment) mirrorView, tag); if (addToBackStack) { transaction.addToBackStack(tag); }/*ww w .jav a2s.c o m*/ transaction.commitAllowingStateLoss(); } else { showFragment(fragmentManager, (Fragment) mirrorView, addToBackStack, tag); } }
From source file:es.rgmf.libresportgps.MainActivity.java
/** * This method is called when user click on track list item in the * TrackListFragment fragment./* w ww. j a va 2s . c o m*/ * * @param track * The track selected. */ @Override public void onTrackSelected(Track track) { TrackDetailFragment tdf = TrackDetailFragment.newInstance(); tdf.setTrack(track); FragmentTransaction transaction = mFragmentManager.beginTransaction(); transaction.replace(R.id.container, tdf); transaction.addToBackStack(null); // Add this fragment to stack because // the user can // back to the latter fragment. transaction.commitAllowingStateLoss(); }
From source file:net.sf.sprockets.app.ui.PanesActivity.java
/** * Use your own layout for the panes.// w w w . j av a 2 s .co m * * @param pagerId {@code R.id} value for the ViewPager in the single pane layout * @param pane1Id {@code R.id} value for the first pane in the multi-pane layout * @param pane2Id {@code R.id} value for the second pane in the multi-pane layout */ public void setContentView(int layoutResId, int pagerId, int pane1Id, int pane2Id) { setContentView(layoutResId); Fragment pane1 = findFragmentByPane(1); Fragment pane2 = findFragmentByPane(2); ViewPager pager = findById(this, pagerId); /* do we need to move the fragments between the single and multi-pane layouts? */ FragmentManager fm = getFragmentManager(); FragmentTransaction ft = null; if (pane2 == null) { pane2 = getFragment(2); } else if (pane2.getId() != (pager != null ? pagerId : pane2Id)) { ft = fm.beginTransaction().remove(pane2); // remove in reverse to preserve indices } if (pane1 == null) { pane1 = getFragment(1); } else if (pane1.getId() != (pager != null ? pagerId : pane1Id)) { if (ft == null) { ft = fm.beginTransaction(); } ft.remove(pane1); } if (ft != null) { ft.commitAllowingStateLoss(); fm.executePendingTransactions(); // force removes so can add to a different container } /* add the fragments to the panes */ if (pager != null) { pager.setAdapter(new PanesAdapter(pane1, pane2)); } else { ft = null; if (pane1.getId() != pane1Id) { ft = Fragments.open(this).add(pane1Id, pane1, PANE_1); } if (pane2.getId() != pane2Id) { if (ft == null) { ft = Fragments.open(this); } ft.add(pane2Id, pane2, PANE_2); } if (ft != null) { ft.commitAllowingStateLoss(); } } }
From source file:com.android.mail.ui.TwoPaneController.java
@Override public void launchFragment(final Fragment fragment, final int selectPosition) { final int containerViewId = TwoPaneLayout.MISCELLANEOUS_VIEW_ID; final FragmentManager fragmentManager = mActivity.getFragmentManager(); if (fragmentManager.findFragmentByTag(TAG_CUSTOM_FRAGMENT) == null) { final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.addToBackStack(null); fragmentTransaction.replace(containerViewId, fragment, TAG_CUSTOM_FRAGMENT); mMiscellaneousViewTransactionId = fragmentTransaction.commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); }/*from w w w .j av a 2 s. c o m*/ if (selectPosition >= 0) { getConversationListFragment().setRawSelected(selectPosition, true); } }
From source file:com.android.mail.ui.TwoPaneController.java
@Override public void showWaitForInitialization() { super.showWaitForInitialization(); FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction(); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); fragmentTransaction.replace(R.id.conversation_list_pane, getWaitFragment(), TAG_WAIT); fragmentTransaction.commitAllowingStateLoss(); }
From source file:com.skubit.comics.activities.MainActivity.java
private void showFragment(Fragment targetFragment, String tag, int position) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction().setTransition(FragmentTransaction.TRANSIT_NONE); hidesFragments(position, transaction); Fragment f = fragments[position];// w w w . j a v a2s .c o m if (f == null) { addFragmentToCache(targetFragment, tag, position); if (isFragmentInCache(tag)) { transaction.show(fragments[position]); } else { transaction.add(R.id.container, fragments[position], tag); } } else { transaction.show(fragments[position]); } transaction.commitAllowingStateLoss(); }
From source file:com.breadwallet.presenter.activities.IntroActivity.java
private void showHideFragments(Fragment... fragments) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.hide(introWelcomeFragment); fragmentTransaction.hide(introNewRecoverFragment); fragmentTransaction.hide(introNewWalletFragment); fragmentTransaction.hide(introRecoverWalletFragment); fragmentTransaction.hide(introWarningFragment); for (Fragment f : fragments) { fragmentTransaction.show(f);// w ww .jav a2s . c o m } fragmentTransaction.commitAllowingStateLoss(); }
From source file:com.abewy.android.apps.klyph.app.MainActivity.java
private void updateContent(int selection) { if (selection != oldSelection) { Bundle bundle = new Bundle(); bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId()); String className = classes.get(selection); if (className.equals("com.abewy.android.apps.klyph.fragment.Chat")) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME); startActivity(intent);// w w w . ja v a2 s. c o m } catch (NameNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI)); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } } else { if (selection < navAdapter.getCount()) setTitle(navAdapter.getItem(selection)); else setTitle(KlyphSession.getSessionUserName()); Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle); if (previousFragment != null) previousFragment.onSetToBack(this); FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.main, fragment, FRAGMENT_TAG); tx.commitAllowingStateLoss(); ((IKlyphFragment) fragment).onSetToFront(this); previousFragment = (IKlyphFragment) fragment; navAdapter.setSelectedPosition(selection); navAdapter.notifyDataSetChanged(); oldSelection = selection; if (notificationsFragment != null) notificationsFragment.setHasOptionsMenu(false); } } }
From source file:com.abewy.android.apps.openklyph.app.MainActivity.java
private void updateContent(int selection) { if (selection != oldSelection) { Bundle bundle = new Bundle(); bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId()); String className = classes.get(selection); if (className.equals("com.abewy.android.apps.openklyph.fragment.Chat")) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME); startActivity(intent);//from w ww . ja va 2 s . co m } catch (NameNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI)); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } } else { if (selection < navAdapter.getCount()) setTitle(navAdapter.getItem(selection)); else setTitle(KlyphSession.getSessionUserName()); Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle); if (previousFragment != null) previousFragment.onSetToBack(this); FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.main, fragment, FRAGMENT_TAG); tx.commitAllowingStateLoss(); ((IKlyphFragment) fragment).onSetToFront(this); previousFragment = (IKlyphFragment) fragment; navAdapter.setSelectedPosition(selection); navAdapter.notifyDataSetChanged(); oldSelection = selection; if (notificationsFragment != null) notificationsFragment.setHasOptionsMenu(false); } } }
From source file:org.bohrmeista.chan.ui.activity.BoardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ChanApplication.getBoardManager().addListener(this); boardLoadable = new Loadable(); threadLoadable = new Loadable(); boardFragment = ThreadFragment.newInstance(this); setBoardFragmentViewMode();//from www. j a va2 s .c om threadFragment = ThreadFragment.newInstance(this); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.left_pane, boardFragment); ft.replace(R.id.right_pane, threadFragment); ft.commitAllowingStateLoss(); final ActionBar actionBar = getActionBar(); boardSpinner = new Spinner(actionBar.getThemedContext()); spinnerAdapter = new BoardSpinnerAdapter(this, boardSpinner); boardSpinner.setAdapter(spinnerAdapter); boardSpinner.setOnItemSelectedListener(this); actionBar.setCustomView(boardSpinner); actionBar.setDisplayShowCustomEnabled(true); updatePaneState(); Intent startIntent = getIntent(); Uri startUri = startIntent.getData(); if (savedInstanceState != null) { threadLoadable.readFromBundle(this, "thread", savedInstanceState); startLoadingThread(threadLoadable); // Reset page etc. Loadable tmp = new Loadable(); tmp.readFromBundle(this, "board", savedInstanceState); startLoadingBoard(new Loadable(tmp.board)); } else { if (startUri != null) { handleIntentURI(startUri); } if (boardLoadable.mode == Loadable.Mode.INVALID) { List<Board> savedValues = ChanApplication.getBoardManager().getSavedBoards(); if (savedValues.size() > 0) { startLoadingBoard(new Loadable(savedValues.get(0).value)); } } } if (startIntent.getExtras() != null) { handleExtraBundle(startIntent.getExtras()); } ignoreNextOnItemSelected = true; }