DEV Community

Discussion on: Communication between Fragment and Activity

Collapse
 
sindrenm profile image
Sindre Moen

If I had a direct reference to the OnboardingFragment somewhere in my activity, I suppose I would prefer the lambda. However, through onAttachFragment you'd need to check the type, which I feel looks kind of ugly.

Also, with the interface, I'd instead have a setter on my fragment instead of checking the type of context. That way, the listener doesn't necessarily need to be an Activity or Context, but anything that implements the interface.