Question

This is my code:

protected void showNewsItem(News news) {
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    DialogFragment newFragment = MyNewsFragment.newInstance();
    newFragment.show(ft, "dialog");
}

and the error This FragmentManager should be recycled after use with #recylce() appears on the beginTransaction line.

I've tried adding fm.recycle(); like the error suggests, but that gives me an error that recycle is undefined.

Was it helpful?

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 idiom is sufficient for showing a DialogFragment.

The show(FragmentTransaction transaction, String tag) version is for "piggybacking" an existing FragmentTransaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top