本文整理汇总了Java中android.app.FragmentTransaction.commitAllowingStateLoss方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.commitAllowingStateLoss方法的具体用法?Java FragmentTransaction.commitAllowingStateLoss怎么用?Java FragmentTransaction.commitAllowingStateLoss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.commitAllowingStateLoss方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showDialogFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private void showDialogFragment(int dialogId, String customMessage) {
if (mDestroyed) {
return;
}
mProgressBar.setIndeterminate(false);
DialogFragment fragment;
switch (dialogId) {
case R.id.dialog_account_setup_error: {
fragment = ConfirmationDialogFragment.newInstance(dialogId,
getString(R.string.account_setup_failed_dlg_title),
customMessage,
getString(R.string.account_setup_failed_dlg_edit_details_action),
getString(R.string.account_setup_failed_dlg_continue_action)
);
break;
}
default: {
throw new RuntimeException("Called showDialog(int) with unknown dialog id.");
}
}
FragmentTransaction ta = getFragmentManager().beginTransaction();
ta.add(fragment, getDialogTag(dialogId));
ta.commitAllowingStateLoss();
// TODO: commitAllowingStateLoss() is used to prevent https://code.google.com/p/android/issues/detail?id=23761
// but is a bad...
//fragment.show(ta, getDialogTag(dialogId));
}
示例2: removeFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void removeFragment(FragmentManager fragmentManager, int containViewId)
{
if(fragmentManager != null) {
Fragment fragment = fragmentManager.findFragmentById(containViewId);
if (fragment != null)
{
fragments.remove(fragment);
// TODO: Remove from backStackKeys
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.remove(fragment);
transaction.commitAllowingStateLoss();
}
}
else {
Log.e("FragmentHelper", "Fragment Manager = null");
}
}
示例3: clearAllBackStackFragments
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void clearAllBackStackFragments(FragmentManager fragmentManager)
{
FragmentTransaction ft = fragmentManager.beginTransaction();
for (WeakReference<Fragment> ref : fragments) {
Fragment fragment = ref.get();
if (fragment != null) {
ft.remove(fragment);
}
}
fragments.clear();
backStackKeys.clear();
ft.commitAllowingStateLoss();
}
示例4: reloadFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void reloadFragment(FragmentManager fragmentManager, Fragment fragment) {
if (fragment != null){
FragmentTransaction ft = fragmentManager.beginTransaction();
// ft.setTransition(-1);
// ft.replace(containViewId, fragment);
ft.detach(fragment);
ft.attach(fragment);
ft.commitAllowingStateLoss();
}
}
示例5: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query, int anim) {
final Bundle args = new Bundle();
args.putInt(EXTRA_TYPE, type);
args.putParcelable(EXTRA_ROOT, root);
args.putParcelable(EXTRA_DOC, doc);
args.putString(EXTRA_QUERY, query);
final FragmentTransaction ft = fm.beginTransaction();
switch (anim) {
case ANIM_SIDE:
args.putBoolean(EXTRA_IGNORE_STATE, true);
break;
case ANIM_DOWN:
ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen);
break;
case ANIM_UP:
ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up);
break;
}
final DirectoryFragment fragment = new DirectoryFragment();
fragment.setArguments(args);
ft.replace(R.id.container_directory, fragment);
ft.commitAllowingStateLoss();
}
示例6: removeFragment
import android.app.FragmentTransaction; //导入方法依赖的package包/类
@SuppressWarnings("SameParameterValue")
private void removeFragment(final Fragment fragment, final boolean addToBackStack,
final boolean allowStateLoss) {
final FragmentManager fm = getFragmentManager();
final FragmentTransaction transaction = fm.beginTransaction();
final String tag;
if (fragment instanceof CurrentFeedFragment) {
tag = CurrentFeedFragment.TAG;
} else if (fragment instanceof FeedSubscriptionsFragment) {
tag = FeedSubscriptionsFragment.TAG;
} else if (fragment instanceof SavedEntriesFragment) {
tag = SavedEntriesFragment.TAG;
} else if (fragment instanceof InitialSetupFragment) {
tag = InitialSetupFragment.TAG;
} else {
tag = LoadCurrentFeedFragment.TAG;
}
transaction.remove(fragment);
if (addToBackStack) {
transaction.addToBackStack(tag);
}
if (allowStateLoss) {
transaction.commitAllowingStateLoss();
} else {
transaction.commit();
}
fm.executePendingTransactions();
}
示例7: replaceHasHistory
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public void replaceHasHistory(int containerId, Fragment fragment) {
if (currentFragment==fragment) {
return;
}
FragmentTransaction ft = fm.beginTransaction();
ft.replace(containerId, fragment);
ft.addToBackStack(null);//添加这个会在按返回键的时候先退出fragment,一些特殊场合可能用到,但效果其实不理想
ft.commitAllowingStateLoss();
currentFragment = fragment;
}
示例8: removeAll
import android.app.FragmentTransaction; //导入方法依赖的package包/类
/**清空所有fragment*/
public void removeAll(){
FragmentTransaction ft = fm.beginTransaction();
for (Fragment f:fs) {
ft.remove(f);
}
ft.commitAllowingStateLoss();
}
示例9: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}
示例10: changeFragmentForTablets
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
if (newFragmentType == FragmentsAvailable.DIALER) {
showStatusBar();
} else {
hideStatusBar();
}
}
emptyFragment = false;
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if(newFragmentType == FragmentsAvailable.EMPTY){
ll.setVisibility(View.VISIBLE);
emptyFragment = true;
transaction.replace(R.id.fragmentContainer2, newFragment);
transaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions();
} else {
if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
ll.setVisibility(View.VISIBLE);
if (newFragmentType == FragmentsAvailable.CONTACT_EDITOR) {
transaction.addToBackStack(newFragmentType.toString());
}
transaction.replace(R.id.fragmentContainer2, newFragment);
} else {
if (newFragmentType == FragmentsAvailable.EMPTY) {
ll.setVisibility(View.VISIBLE);
transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
emptyFragment = true;
}
if (newFragmentType == FragmentsAvailable.DIALER
|| newFragmentType == FragmentsAvailable.ABOUT
|| newFragmentType == FragmentsAvailable.SETTINGS
|| newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
ll.setVisibility(View.GONE);
} else {
ll.setVisibility(View.VISIBLE);
transaction.replace(R.id.fragmentContainer2, new EmptyFragment());
}
/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
if (newFragmentType.isRightOf(currentFragment)) {
transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right);
} else {
transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left);
}
}*/
transaction.replace(R.id.fragmentContainer, newFragment);
}
transaction.commitAllowingStateLoss();
getFragmentManager().executePendingTransactions();
currentFragment = newFragmentType;
if (newFragmentType == FragmentsAvailable.DIALER
|| newFragmentType == FragmentsAvailable.SETTINGS
|| newFragmentType == FragmentsAvailable.CONTACTS_LIST
|| newFragmentType == FragmentsAvailable.CHAT_LIST
|| newFragmentType == FragmentsAvailable.HISTORY_LIST) {
try {
getFragmentManager().popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (IllegalStateException e) {
}
}
fragmentsHistory.add(currentFragment);
}
}
示例11: replaceFragmentVideoByAudio
import android.app.FragmentTransaction; //导入方法依赖的package包/类
private void replaceFragmentVideoByAudio() {
audioCallFragment = new CallAudioFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragmentContainer, audioCallFragment);
try {
transaction.commitAllowingStateLoss();
} catch (Exception e) {
}
}
示例12: addFragmentToActivity
import android.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*
* @param fragmentManager {@link FragmentManager} associated with {@link android.app.Activity}.
* @param fragment {@link Fragment} to add.
* @param tag A string identifying the fragment.
*/
public static void addFragmentToActivity(@NonNull final FragmentManager fragmentManager,
@NonNull final Fragment fragment,
@NonNull final String tag) {
checkNotNull(fragmentManager, "fragmentManager must not be null!");
checkNotNull(fragment, "fragment must not be null!");
checkNotNull(tag, "tag must not be null!");
checkArgument(!tag.isEmpty(), "tag string must not be empty!");
removeFragment(fragmentManager, tag);
final FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(fragment, tag);
transaction.commitAllowingStateLoss();
}
示例13: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
public static void show(FragmentManager fm) {
final HomeFragment fragment = new HomeFragment();
final FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container_directory, fragment, TAG);
ft.commitAllowingStateLoss();
}
示例14: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}
示例15: show
import android.app.FragmentTransaction; //导入方法依赖的package包/类
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();
}