Skip to content

Problem with retained fragments #1

@luizfp

Description

@luizfp

I implemented the worker fragment approach in my project based in your 'extra' of this project.

I have Activity A that has a Fragment A. That fragment starts a worker fragment.

But, if I start some other activity and come back to Activity A, I get this
exception:

java.lang.IllegalStateException: Failure saving state: "WorkerFragment" has target not in fragment manager: "FragmentA"

I googled about this and the workaround for that problem was to put in
onDetach() of my Fragment A this: workerFragment.setTargetFragment(null, -1);

But, if now I open another activity and come back to Activity A, then, rotates
the screen, I get an exception, because now, of course, getTargetFragment() == null.

So, I added this verification in onAttach() of Worker fragment: if (getTargetFragment() != null) {}

In this way, I don't get any exceptions, but I need to know: Is this the expected behavior or I'm missing something?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions