本文整理汇总了Java中android.support.v4.app.FragmentTransaction.commitAllowingStateLoss方法的典型用法代码示例。如果您正苦于以下问题:Java FragmentTransaction.commitAllowingStateLoss方法的具体用法?Java FragmentTransaction.commitAllowingStateLoss怎么用?Java FragmentTransaction.commitAllowingStateLoss使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.FragmentTransaction
的用法示例。
在下文中一共展示了FragmentTransaction.commitAllowingStateLoss方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reloadData
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 重新加载数据
*
* @param newListFragments 新的fragment集合
* @param newSelectedList 新的选中分类集合
*/
public void reloadData(List<? extends BaseFragment> newListFragments, List<ColumnBean> newSelectedList) {
// 每次刷新顺序都需要清除缓存
if (mListFragments.size() > 0) {
FragmentTransaction ft = mFm.beginTransaction();
for (Fragment f :
mListFragments) {
ft.remove(f);
}
ft.commitAllowingStateLoss();
mFm.executePendingTransactions();
}
// 清除原有数据源
mListFragments.clear();
mSelectedList.clear();
// 重新添加数据源
mListFragments.addAll(newListFragments);
mSelectedList.addAll(newSelectedList);
// 刷新数据
notifyDataSetChanged();
}
示例2: addFragments
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void addFragments(Fragment... fragments) {
if (fragments != null && fragments.length != 0) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
for (Fragment fragment : fragments) {
if (fragment instanceof LetvFragmentListener) {
LetvFragmentListener listener = (LetvFragmentListener) fragment;
String tag = listener.getTagName();
if (!TextUtils.isEmpty(tag)) {
int fragmentRes = listener.getContainerId();
if (fragmentRes > 0 && fragmentManager.findFragmentByTag(tag) == null) {
transaction.add(fragmentRes, fragment, tag);
}
}
}
}
try {
transaction.commitAllowingStateLoss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例3: changeFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void changeFragment(FragmentActivity activity, Fragment nextFragment, boolean addToBackStack) {
String name = nextFragment.getClass().getSimpleName();
final FragmentManager fragmentManager = activity.getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_left_in, R.anim.slide_right_in, R.anim.slide_left_out, R.anim.slide_right_out);
fragmentTransaction.replace(R.id.frame_content, nextFragment);
if (addToBackStack) {
fragmentTransaction.addToBackStack(name);
}
try {
fragmentTransaction.commitAllowingStateLoss();
fragmentManager.executePendingTransactions();
} catch (IllegalStateException e) {
}
}
示例4: showAlreadyOpenDialog
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@TargetApi(17)
private void showAlreadyOpenDialog() {
FragmentManager fm = getSupportFragmentManager();
if (fm != null && getActivity() != null && !getActivity().isDestroyed()) {
FragmentTransaction ft = fm.beginTransaction();
this.mAlipayAutoPayAlreadyOpenDialog = (AlipayAutoPayAlreadyOpenDialog) fm.findFragmentByTag("showmAlipayAutoPayAlreadyOpenDialog");
if (this.mAlipayAutoPayAlreadyOpenDialog == null) {
this.mAlipayAutoPayAlreadyOpenDialog = new AlipayAutoPayAlreadyOpenDialog();
} else {
ft.remove(this.mAlipayAutoPayAlreadyOpenDialog);
}
this.mAlipayAutoPayAlreadyOpenDialog.setAlipayConfirmCallback(this);
ft.add(this.mAlipayAutoPayAlreadyOpenDialog, "showmAlipayAutoPayAlreadyOpenDialog");
ft.commitAllowingStateLoss();
}
}
示例5: finish
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void finish() {
super.finish();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
for (int key : sActualFragments.keySet()) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(key + "_key");
if (fragment != null) {
fragmentTransaction.remove(fragment);
}
}
fragmentTransaction.commitAllowingStateLoss();
if (mAdsFetcher != null) {
mAdsFetcher.cancel();
}
RootUtils.closeSU();
}
示例6: onSwitchInputUrl
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
@Override
public void onSwitchInputUrl() {
setCenterTitle("输入地址");
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
hiddenOnLineFragment(ft);
hiddenLocalVideoFragment(ft);
hiddenLocalVideoPlayGoFragment(ft);
hiddenOutlineFragment(ft);
if(inputUrlFragment==null){
inputUrlFragment = new InputUrlFragment();
ft.add(getUserContentHolder().getContainer().getId(),inputUrlFragment);
}else{
ft.show(inputUrlFragment);
}
ft.commitAllowingStateLoss();
}
示例7: showFilterDialog
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void showFilterDialog(FragmentManager fm, boolean isMuzei) {
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag(TAG);
if (prev != null) {
ft.remove(prev);
}
ft.add(newInstance(isMuzei), TAG)
.setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
try {
ft.commit();
} catch (IllegalStateException e) {
ft.commitAllowingStateLoss();
}
}
示例8: processRestoreInstanceState
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void processRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null) {
FragmentTransaction ft = mFragment.getFragmentManager().beginTransaction();
if (mIsHidden) {
ft.hide(mFragment);
} else {
ft.show(mFragment);
}
ft.commitAllowingStateLoss();
}
}
示例9: replaceFragmentWithBackStack
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* 替换fragement 并添加动画
* 替换fragement的同时对fragment进行“入back栈”操作 ,据我所知并不是真正的进入内存栈
*
* @param id_content
* @param anim_in
* @param anim_out
* @param fragment
*/
@Deprecated
public void replaceFragmentWithBackStack(@IdRes int id_content, @AnimRes int anim_in, @AnimRes int anim_out, Fragment fragment) {
String tag = fragment.getClass().getSimpleName();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// transaction.setCustomAnimations(anim_in, anim_out);
transaction.replace(id_content, fragment, tag);
//记录commit一次操作,与mFragmentManager.popBackStack();匹配使用
transaction.addToBackStack(tag);
//commitAllowingStateLoss 优于 commit 方法,当使用commit方法时,系统将进行状态判断,如果状态(mStateSaved)已经保存,将发生"Can not perform this action after onSaveInstanceState"错误。
//如果mNoTransactionsBecause已经存在,将发生"Can not perform this action inside of " + mNoTransactionsBecause错误。
transaction.commitAllowingStateLoss();
}
示例10: onCreate
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ad);
String type = getIntent().getStringExtra("type");
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, BetListFragment.newInstance(1, type));
transaction.commitAllowingStateLoss();
}
示例11: show
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public static void show(FragmentManager fm, DocumentInfo doc) {
final Bundle args = new Bundle();
args.putParcelable(EXTRA_DOC, doc);
final DetailFragment fragment = new DetailFragment();
fragment.setArguments(args);
final FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.container_info, fragment, TAG_DETAIL);
ft.commitAllowingStateLoss();
}
示例12: removeDialogFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
protected void removeDialogFragment(){
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
List<Fragment> fragments=fm.getFragments();
if (fragments==null){
return;
}
for (Fragment fragment:fragments){
if (fragment instanceof DialogFragment){
ft.remove(fragment);
}
}
ft.commitAllowingStateLoss();
}
示例13: removeCurrentFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
private void removeCurrentFragment() {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment currentFrag = getSupportFragmentManager()
.findFragmentById(R.id.mainContainer);
if (currentFrag != null) {
transaction.remove(currentFrag);
}
transaction.commitAllowingStateLoss();
}
示例14: replaceFragment
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
public void replaceFragment(Fragment fragment, final boolean addToBackStack) {
final String fragmentName = fragment.getClass().getName();
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (addToBackStack) {
ft.addToBackStack(fragmentName);
}
ft.replace(getFragmentTransactionReplacementResource(), fragment, fragmentName);
if (!(this.isDestroyed() || isFinishing())) {
ft.commitAllowingStateLoss();
}
}
示例15: addFragmentToActivity
import android.support.v4.app.FragmentTransaction; //导入方法依赖的package包/类
/**
* The {@code fragment} is added to the container view with id {@code frameId}. The operation is
* performed by the {@code fragmentManager}.
*/
public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager,
@NonNull Fragment fragment, int frameId, String tag, int enterAnimation, int exitAnimation,
int popEnter, int popExit) {
checkNotNull(fragmentManager);
checkNotNull(fragment);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(enterAnimation, exitAnimation, popEnter, popExit);
fragmentTransaction.replace(frameId, fragment, tag);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commitAllowingStateLoss();
}