我收到错误消息“ onSaveInstanceState之后无法执行此操作”。我知道简单的修复方法是使用commitAllowingStateLoss,但就我而言,背景管理器正在创建此Fragment。如何避免此错误?
android.app.BackStackRecord.commitInternal(BackStackRecord.java:707)
at android.app.BackStackRecord.commit(BackStackRecord.java:671) at android.support.v17.leanback.app.BackgroundManager.createFragment(BackgroundManager.java:596)
at android.support.v17.leanback.app.BackgroundManager.<init>(BackgroundManager.java:587)
在onCreate()方法中,我调用prepareBackgroundManager()。
private void prepareBackgroundManager() {
if (!requireActivity().isFinishing()) {
mBackgroundManager = BackgroundManager.getInstance(requireActivity());
if (mBackgroundManager != null && !mBackgroundManager.isAttached()) {
mBackgroundManager.attach(requireActivity().getWindow());
}
}
}