This Project offers a
simple but clear Android showcase project designed with
MVP Pattern (or MVP Framework), which comes to become a more and more important
design pattern in Android application project. Besides,
MVP used project is easy to changed into
MVVM, the future of Android Project.
What is MVP?
Activity and Fragment take most parts of Android Developing jobs.
In traditional Android project, we often write business code and manipulate views directly inside Activity or Fragment. In this case, it is easy to write codes but the Activity or Fragment will become more and more complicated. It takes efforts to read and change. (We usually call this Android standard code style
With MVP pattern, the Activity will be just activity, which only does the job of "Find View", "Set Listener" and "React to the LifeCycle". The jobs of UI Logic will be moved to IView, while the jobs of Business Logic will be moved to IPresenter. In this case, the Activity remains very simple and clear, so that it is read-friendly. And since the business logic is written in Presenter, it can be reused in other Activity easily.
By UML, it looks like
"Keep It Stupid Simple". MVP will make the Activity or Fragment much simpler, which means that it is easy to read and change.
Avoid Leak in Background Task
The code of business logic is moved to Presenter. So that all the background tasks (such as HTTP request, File operating) can be written here. We can remove the reference of Activity in Presenter when onDestroy. Since we have separated this tasks from Activity, the Activity will not easily leak when it is onDestroy.
This Project is a sample project used in the following post in my Blog (Android MVP 模式 简单易懂的介绍方式). The package structure is as the following table.
|login||Simple MVP usage in Login|
|loginoptimized||Simple MVP usage in Login, avoid Activity leak|
|outteradapter||MVP usage in Adapter|
|eventbus||MVP usage with EventBus|
|fragments||MVP usage in ViewPager|
Give MVP a try, tell your friends!
- android-lockpattern discreteSeekBar 公共技术点之 View 绘制流程 android-Ultra-Pull-To-Refresh BaseAdapterHelper xUtils 公共技术点之 Java 反射 Reflection 公共技术点之 Android 动画基础 公共技术点之 Java 注解 Annotation Dagger cling DynamicLoadApk Side Menu.Android PhotoView Jave Proxy CircularFloatingActionMenu 公共技术点之 View 事件传递 Android-Universal-Image-Loader PagerSlidingTabStrip CalendarListView HoloGraphLibrary 公共技术点之依赖注入 Volley EventBus NineOldAnimations ViewPagerIndicator SlidingMenu