这个FragmentManager在使用完后应该通过#recycle()进行回收。

3
这是我的代码:
protected void showNewsItem(News news) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    DialogFragment newFragment = MyNewsFragment.newInstance();
    newFragment.show(ft, "dialog");
}

当在 beginTransaction 行出现错误 This FragmentManager should be recycled after use with #recylce() 时。

我尝试按照错误提示添加 fm.recycle();,但这给我带来了一个错误,即 recycle 未定义。

1个回答

4
请使用DialogFragment.show(FragmentManager manager, String tag)版本。在您的情况下:
protected void showNewsItem(News news) {
    DialogFragment newFragment = MyNewsFragment.newInstance();
    newFragment.show(getFragmentManager(), "dialog");
}

通常,以上习语足以显示一个DialogFragmentshow(FragmentTransaction transaction, String tag)版本用于“搭便车”现有的FragmentTransaction

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接