Skip to content Skip to sidebar Skip to footer

Why Do Fragments Detach From Their Activity?

Like many others, I'm struggling with this error: java.lang.IllegalStateException: Fragment xyz not attached to Activity This question offers some ideas on how to deal with this.

Solution 1:

Because Android supposes that Activities may be destroyed and recreated to accommodate configuration changes. Fragments, in contrast, are not.

Is it to be expected that the Fragment is not even necessarily attached to its Activity during its own onCreate() method?

Yes, it is "expected." Bad design IMO, but expected.

Post a Comment for "Why Do Fragments Detach From Their Activity?"