- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
java.lang.IllegalStateException: FragmentManager is already executing transactions
我已经阅读了所有关于 StackOverflow 的问题,但没有任何帮助。只是想分享我的经验
public void onResume() {
super.onResume()
if(condition) replaceFragment()
}
public void replaceFragment() {
if (fragmentName != null && !this.isDestroyed()) {
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(container_id, FragmentInstantiate());
ft.commitAllowingStateLoss();
}
}
是 commit()/commitAllowingStateLoss() 导致了 IllegalStateException: FragmentManager already executing transactions。不是 commitNow() 或 executePendingTransactions()
最佳答案
问题:问题是在 Fragment.onResume() 方法中 同步 执行 replaceFragment()。
override fun onResume() {
super.onResume()
if(condition) replaceFragment()
}
解决方案
override fun onResume() {
super.onResume()
if(condition) {
Observable.fromCallable{}
.observeOn(AndroidSchedulers.mainThread())
.subscribe { replaceFragment() }
}
或者使用Handler延迟replaceFragment()的执行
new Handler().post { replaceFragment() };
关于android - FragmentManager 已经在 commitAllowingStateLoss() 上执行事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49529529/
我在 Activity 的 onCreate() 方法中调用了 popBackStack(),但是我得到了异常: Caused by java.lang.IllegalStateException:
我在显示 DialogFragment 时遇到 IllegalStateException : java.lang.IllegalStateException: Can not perform thi
java.lang.IllegalStateException: FragmentManager is already executing transactions 我已经阅读了所有关于 StackO
我的应用使用 fragment Activity ,它仅处于纵向模式,无法旋转屏幕。 最初我使用的是 commit() 方法,但现在我打算不加选择地将这些更改为 commitAllowingState
我想在网络后台操作后提交一个 fragment 。我在成功的网络操作后调用了 commit(),但如果 Activity 进入暂停或停止状态,它会导致应用程序崩溃,说 IllegalState 异常。
上下文:我有一个Activity,其中包含一个Fragment 和3 个InnerFragments。当调用 Fragment onDestroy() 时,我想从 FragmentManager 中删
我在我的项目中使用了使用 fragment 构建它的提交方法。 无论如何,有时我得到 IllegalStateException: Can not perform this action after
之前我们显示下面的DialogFragment没有问题 // Triggered by button click. private void openFromCloud() { Lo
我是一名优秀的程序员,十分优秀!