Java Code Examples for android.app.FragmentTransaction#commitAllowingStateLoss()

The following examples show how to use android.app.FragmentTransaction#commitAllowingStateLoss() . 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: DialtactsActivity.java    From coursera-android with MIT License 6 votes vote down vote up
/**
 * Add search fragment.  Note this is called during onLayout, so there's some restrictions,
 * such as executePendingTransaction can't be used in it.
 */
private void addSearchFragment() {
    // In order to take full advantage of "fragment deferred start", we need to create the
    // search fragment after all other fragments are created.
    // The other fragments are created by the ViewPager on the first onMeasure().
    // We use the first onLayout call, which is after onMeasure().

    // Just return if the fragment is already created, which happens after configuration
    // changes.
    if (mSearchFragment != null) return;

    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment searchFragment = new PhoneNumberPickerFragment();

    searchFragment.setUserVisibleHint(false);
    ft.add(R.id.dialtacts_frame, searchFragment);
    ft.hide(searchFragment);
    ft.commitAllowingStateLoss();
}
 
Example 2
Source File: CallActivity.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void replaceFragmentVideoByAudio() {
	audioCallFragment = new CallAudioFragment();
	FragmentTransaction transaction = getFragmentManager().beginTransaction();
	transaction.replace(R.id.fragmentContainer, audioCallFragment);
	try {
		transaction.commitAllowingStateLoss();
	} catch (Exception e) {
	}
}
 
Example 3
Source File: ServerFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, RootInfo root) {
    final ServerFragment fragment = new ServerFragment();
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_ROOT, root);
    fragment.setArguments(args);
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 4
Source File: MoveFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, ArrayList<DocumentInfo> docs, boolean deleteAfter) {
	final Bundle args = new Bundle();
	args.putParcelableArrayList(EXTRA_DOC_LIST, docs);
	args.putBoolean(EXTRA_DELETE_AFTER, deleteAfter);
	
	final MoveFragment fragment = new MoveFragment();
	fragment.setArguments(args);

	final FragmentTransaction ft = fm.beginTransaction();
	ft.replace(R.id.container_save, fragment, TAG);
	ft.commitAllowingStateLoss();
}
 
Example 5
Source File: BaseRestoreInstanceFragment.java    From Material-SearchView with Apache License 2.0 5 votes vote down vote up
public void show(@NonNull final FragmentManager manager) {
    FragmentTransaction transaction = manager.beginTransaction();
    Fragment prev = manager.findFragmentByTag(DIALOG_TAG);
    if (prev != null) {
        transaction.remove(prev);
    }

    transaction.add(this, DIALOG_TAG);
    transaction.commitAllowingStateLoss();
    manager.executePendingTransactions();
}
 
Example 6
Source File: RootsFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, Intent includeApps) {
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_INCLUDE_APPS, includeApps);

    final RootsFragment fragment = new RootsFragment();
    fragment.setArguments(args);

    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_roots, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 7
Source File: MoveFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, ArrayList<DocumentInfo> docs, boolean deleteAfter) {
	final Bundle args = new Bundle();
	args.putParcelableArrayList(EXTRA_DOC_LIST, docs);
	args.putBoolean(EXTRA_DELETE_AFTER, deleteAfter);
	
	final MoveFragment fragment = new MoveFragment();
	fragment.setArguments(args);

	final FragmentTransaction ft = fm.beginTransaction();
	ft.replace(R.id.container_save, fragment, TAG);
	ft.commitAllowingStateLoss();
}
 
Example 8
Source File: CallActivity.java    From Linphone4Android with GNU General Public License v3.0 5 votes vote down vote up
private void replaceFragmentAudioByVideo() {
//		Hiding controls to let displayVideoCallControlsIfHidden add them plus the callback
		videoCallFragment = new CallVideoFragment();

		FragmentTransaction transaction = getFragmentManager().beginTransaction();
		transaction.replace(R.id.fragmentContainer, videoCallFragment);
		try {
			transaction.commitAllowingStateLoss();
		} catch (Exception e) {
		}
	}
 
Example 9
Source File: RootsFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, Intent includeApps) {
    final Bundle args = new Bundle();
    args.putParcelable(EXTRA_INCLUDE_APPS, includeApps);

    final RootsFragment fragment = new RootsFragment();
    fragment.setArguments(args);

    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_roots, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 10
Source File: SaveFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm, String mimeType, String displayName) {
	final Bundle args = new Bundle();
	args.putString(EXTRA_MIME_TYPE, mimeType);
	args.putString(EXTRA_DISPLAY_NAME, displayName);

	final SaveFragment fragment = new SaveFragment();
	fragment.setArguments(args);

	final FragmentTransaction ft = fm.beginTransaction();
	ft.replace(R.id.container_save, fragment, TAG);
	ft.commitAllowingStateLoss();
}
 
Example 11
Source File: FragmentUtil.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**清空所有除了带此tag的fragment*/
public void removeAllExcept(String tag){
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f:fs) {
        if(f.getTag()!=null&&!f.getTag().equals(tag))ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}
 
Example 12
Source File: FragmentTransactionUriRequest.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
@Override
public boolean startFragment(@NonNull UriRequest request, @NonNull Bundle bundle) throws ActivityNotFoundException, SecurityException {
    String fragmentClassName = request.getStringField(FragmentTransactionHandler.FRAGMENT_CLASS_NAME);
    if (TextUtils.isEmpty(fragmentClassName)) {
        Debugger.fatal("FragmentTransactionHandler.handleInternal()应返回的带有ClassName");
        return false;
    }
    if (mContainerViewId == 0) {
        Debugger.fatal("FragmentTransactionHandler.handleInternal()mContainerViewId");
        return false;
    }
    try {
        Fragment fragment = Fragment.instantiate(request.getContext(), fragmentClassName, bundle);
        if (fragment == null) {
            return false;
        }

        FragmentTransaction transaction = mFragmentManager.beginTransaction();
        switch (mStartType) {
            case TYPE_ADD:
                transaction.add(mContainerViewId, fragment, mTag);
                break;
            case TYPE_REPLACE:
                transaction.replace(mContainerViewId, fragment, mTag);
                break;
        }
        if (mAllowingStateLoss) {
            transaction.commitAllowingStateLoss();
        } else {
            transaction.commit();
        }
        return true;
    } catch (Exception e) {
        Debugger.e(e);
        return false;
    }
}
 
Example 13
Source File: PickFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void show(FragmentManager fm) {
    final PickFragment fragment = new PickFragment();

    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_save, fragment, TAG);
    ft.commitAllowingStateLoss();
}
 
Example 14
Source File: AccessTokenListFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * トークンデータの詳細を表示する.
 * @param token トークンデータ
 */
private void openAccessTokenDescription(final SQLiteToken token) {
    AccessTokenDescriptionFragment f = new AccessTokenDescriptionFragment();
    Bundle bundle = new Bundle();
    bundle.putString(AccessTokenDescriptionFragment.EXTRA_CLIENT_ID,
            token.getClientId());
    f.setArguments(bundle);
    FragmentManager fm = getActivity().getFragmentManager();
    FragmentTransaction t = fm.beginTransaction();
    t.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    t.add(android.R.id.content, f, "description");
    t.addToBackStack("tokenList");
    t.commitAllowingStateLoss();
}
 
Example 15
Source File: Utility.java    From scene with Apache License 2.0 5 votes vote down vote up
public static void commitFragment(@NonNull FragmentManager fragmentManager, @NonNull FragmentTransaction transaction, boolean commitNow) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        if (commitNow) {
            transaction.commitNowAllowingStateLoss();
        } else {
            transaction.commitAllowingStateLoss();
        }
    } else {
        transaction.commitAllowingStateLoss();
        if (commitNow) {
            fragmentManager.executePendingTransactions();
        }
    }
}
 
Example 16
Source File: ConnectionsFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static void show(FragmentManager fm) {
    final ConnectionsFragment fragment = new ConnectionsFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment, TAG);
    ft.commitAllowingStateLoss();
}
 
Example 17
Source File: AssistantActivity.java    From Linphone4Android with GNU General Public License v3.0 4 votes vote down vote up
private void changeFragment(Fragment newFragment) {
	hideKeyboard();
	FragmentTransaction transaction = getFragmentManager().beginTransaction();
	transaction.replace(R.id.fragment_container, newFragment);
	transaction.commitAllowingStateLoss();
}
 
Example 18
Source File: RecentsCreateFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static void show(FragmentManager fm) {
    final RecentsCreateFragment fragment = new RecentsCreateFragment();
    final FragmentTransaction ft = fm.beginTransaction();
    ft.replace(R.id.container_directory, fragment);
    ft.commitAllowingStateLoss();
}
 
Example 19
Source File: DialtactsActivity.java    From coursera-android with MIT License 4 votes vote down vote up
/**
 * Hides every tab and shows search UI for phone lookup.
 */
private void enterSearchUi() {
    if (mSearchFragment == null) {
        // We add the search fragment dynamically in the first onLayoutChange() and
        // mSearchFragment is set sometime later when the fragment transaction is actually
        // executed, which means there's a window when users are able to hit the (physical)
        // search key but mSearchFragment is still null.
        // It's quite hard to handle this case right, so let's just ignore the search key
        // in this case.  Users can just hit it again and it will work this time.
        return;
    }
    if (mSearchView == null) {
        prepareSearchView();
    }

    final ActionBar actionBar = getActionBar();

    final Tab tab = actionBar.getSelectedTab();

    // User can search during the call, but we don't want to remember the status.
    if (tab != null && !DialpadFragment.phoneIsInUse()) {
        mLastManuallySelectedFragment = tab.getPosition();
    }

    mSearchView.setQuery(null, true);

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    updateFakeMenuButtonsVisibility(false);

    for (int i = 0; i < TAB_INDEX_COUNT; i++) {
        sendFragmentVisibilityChange(i, false /* not visible */ );
    }

    // Show the search fragment and hide everything else.
    mSearchFragment.setUserVisibleHint(true);
    final FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.show(mSearchFragment);
    transaction.commitAllowingStateLoss();
    mViewPager.setVisibility(View.GONE);

    // We need to call this and onActionViewCollapsed() manually, since we are using a custom
    // layout instead of asking the search menu item to take care of SearchView.
    mSearchView.onActionViewExpanded();
    mInSearchUi = true;
}
 
Example 20
Source File: MainActivity.java    From linphone-android with GNU General Public License v3.0 4 votes vote down vote up
protected void changeFragment(Fragment fragment, String name, boolean isChild) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    if (transaction.isAddToBackStackAllowed()) {
        int count = fragmentManager.getBackStackEntryCount();
        if (count > 0) {
            FragmentManager.BackStackEntry entry =
                    fragmentManager.getBackStackEntryAt(count - 1);

            if (entry != null && name.equals(entry.getName())) {
                fragmentManager.popBackStack();
                if (!isChild) {
                    // We just removed it's duplicate from the back stack
                    // And we want at least one in it
                    transaction.addToBackStack(name);
                }
            }
        }

        if (isChild) {
            transaction.addToBackStack(name);
        }
    }

    if (getResources().getBoolean(R.bool.hide_bottom_bar_on_second_level_views)) {
        if (isChild) {
            if (!isTablet()) {
                hideTabBar();
            }
        } else {
            showTabBar();
        }
    }

    Compatibility.setFragmentTransactionReorderingAllowed(transaction, false);
    if (isChild && isTablet()) {
        transaction.replace(R.id.fragmentContainer2, fragment, name);
        findViewById(R.id.fragmentContainer2).setVisibility(View.VISIBLE);
    } else {
        transaction.replace(R.id.fragmentContainer, fragment, name);
    }
    transaction.commitAllowingStateLoss();
    fragmentManager.executePendingTransactions();
}