What are the possibilities of values in fragment's onAttach

64 Views Asked by At

As we all know, the onAttach(Activity) method was deprecated and onAttach(Context) is now supposed to be used.

My question is - Won't the context of onAttach always be Activity? What else can a fragment be attached to if not Activity?

1

There are 1 best solutions below

1
On

Analyzing source code we can see that the parameter doesn't do anything. If you watch deeper to FragmentHostCallback you can see that context and activity can be different for fragment. (I don't understand why and how but the implementation shows such possibility). And the comment above the FragmentHostCallback tell us that "Fragments may be hosted by any object".