Original post https://github.com/onmyway133/blog/issues/108
There's always need for communication, right 😉 Suppose we have OnboardingActivity that...
For further actions, you may consider blocking this person and/or reporting abuse
If I had a direct reference to the
OnboardingFragmentsomewhere in my activity, I suppose I would prefer the lambda. However, throughonAttachFragmentyou'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.Have you found a clean way of implementing a Coordinator/Flow Controller pattern on Android? Seems like you'd have one Activity as the flow controller and multiple fragments that communicate back to the Activity. Since the Lambda doesn't work I suppose the delegate pattern would be best.
As a side note I should really get into Kotlin, it's so Swift-like that it took me a few seconds to realize this was an Android article.