GDG Geneva is a small GDG, but we try hard 😊 Last Monday we had our July event, and, despite the tremendous heat, spent more than one hour talking about MVP on Android.
I prepared a small Android app to demonstrate how we can create an app that fetches data from a backend and shows them in a list, using two different design approaches:
- !Good Old GOD Activity
Both versions are identical from a user point of view: same UI, same UX. What’s different is the code quality and maintainability, of course.
Everything is in the Activity, because… why not!?
It’s easier and quicker to have everything in one place and if I need a Context I can use this.
The Retrofit network call is synchronous and we dodge the NetworkOnMainThread exception using an AsyncTask. The API client is created in the Activity, like every other needed component.
If you are like me, this approach keeps you awake at night or, even worse, gives you nightmares the moment you close your eyes.
Model-View-Presenter is the new standard de-facto on Android. In this version of the app, I tried to make the view as dumbest as possible, move as much as possible away from it and into a pure-Java codebase. Being pure-Java, we can easily test it without firing any Android device or emulator or using Robolectric.
I used Dagger2, RxJava, ButterKnife also to give an overview about common Android dev tools. Kotlin has been used in the test environment to show how you can start using the new language (read Our Savior) just for your tests and then move to a full Kotlin code base when you feel ready.
App source code is available here:
Slides are available here: