A detailed guide on developing Android apps using the Clean Architecture pattern
Dario Miličić
53143

Hi Dario,

thanks a lot for this great article — it was a lot clearer and more hands-on than others I have read over the months.

One question, if you don’t mind: Where do you stand with regards to Fragments. I see that in you example project you only use one Fragment and that is the DatePickerFragment.

Do you use Fragments within Activities (vs. as dialogs) at all? If you do, is it still the Activity that implements `XPresenter.View` and that just forwards everything to the Fragments? Or do the Fragments themselves implement `YPresenter.View` and the Activity is only there as a “dumb” container? Or something in between? And in any case, how to the Fragments communicate with each other — through the Activity or through a (e. g.) shared Presenter?

I am asking because I have done both and none feels entirely right: In the first case I have one more step of indirection (Presenter -> Activity -> Fragment) and the added complexity of the Fragment life cycle. In the second case the Activity itself becomes mostly useless — that wouldn’t be so bad if the Fragments then were really re-usable components that could be used in various contexts (e. g. one after the other in a phone app, but side by side in a tablet app). But I have found that to rarely be the case — there is always something that needs to be tweaked for the new Activity layout.

Consequently, as more and more logic moves out of the Activities and Fragments (and into Presenters, etc.) I find it more attractive to just stop using Fragments entirely and have the Activity manage all the Views.

Sorry for this rambling question but I think I really need to figure out what to do about Fragments before I can be satisfied with the architecture of my Android apps.

Thanks again and any thoughts are much appreciated!

David