我正在使用嵌套片段。我的代码如下:
private void createGrid(List<App> appList) {
if(appGridView!=null){
getChildFragmentManager().beginTransaction().remove(appGridView).commitAllowingStateLoss();
getChildFragmentManager().executePendingTransactions();
}
appGridView = new AppGridView();
getChildFragmentManager().beginTransaction().add(R.id.frame_top_app_grid, appGridView).commitAllowingStateLoss();}
我还将其添加到我的代码中:
@Override
public void onDetach() {
super.onDetach();
// for bug fixing java.lang.IllegalStateException: Activity has been destroyed
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
但是ACRA报告了我这次事故:
java.lang.IllegalStateException: Activity has been destroyed
at android.support.v4.app.FragmentManagerImpl.enqueueAction(SourceFile:1376)
at android.support.v4.app.BackStackRecord.commitInternal(SourceFile:595)
at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(SourceFile:578)
请帮我解决这个问题。
答案 0 :(得分:0)
我将createGrid放入:
if(isadded){
creategrid()
}else{
recreate activity
}
问题解决了。