This FragmentManager should be recycled after using #recylce()…. here is a solution to the problem.
This FragmentManager should be recycled after using #recylce().
Here is my code :
protected void showNewsItem(News news) {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
DialogFragment newFragment = MyNewsFragment.newInstance();
newFragment.show(ft, "dialog");
}
This FragmentManager should be recycled after use with #recylce()
error appears on the beginTransaction
line.
I’ve tried adding fm.recycle();
Just like the error message, but this gives me the error that recycle
is undefined.
Solution
Use the DialogFragment.show (FragmentManager manager, String tag)
version instead.
So in your case:
protected void showNewsItem(News news) {
DialogFragment newFragment = MyNewsFragment.newInstance();
newFragment.show(getFragmentManager(), "dialog");
}
Usually, the above idiomatic usage is enough to display DialogFragment
.
The show (FragmentTransaction transaction, String tag)
version is used to “carry” existing FragmentTransaction
.