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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If I had a direct reference to the
OnboardingFragment
somewhere in my activity, I suppose I would prefer the lambda. However, throughonAttachFragment
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.