3

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.

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
Darren
  • 10,182
  • 20
  • 95
  • 162

1 Answers1

4

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.

Edmond C
  • 520
  • 1
  • 5
  • 16