The practice of programming with MVP mode on Android

Source: Internet
Author: User

First of all, who is V? Who is P? (M I don't think it's a problem)

View, should be the implementation of the display logic, in the development of Android, we think that fragment, activity can be considered as view, their main task is to control the display logic, this part of the code is not very often reused. View realizes the business by invoking the business logic of P. The business includes synchronous business (which can be manipulated in the UI thread) and asynchronous tasks (such as network, disk IO, and other time-consuming operations), and responds to changes in the UI based on the business return results of P.

For the implementation of presenter, we use the Ebean implementation of the Androidannotations framework (if you are unfamiliar with this framework, Google). For asynchronous tasks, it is done through the @background tag of AA, and his implementation principle is that the task is dispatched through a thread pool. For the return result of the asynchronous task, we have customized a view tag to go back through the interface (view can even not implement the interface, of course there is no callback). So whether the view call presenter, or presenter callback view, are implemented through the interface, completely stripped of the coupling between the two, the P-layer business can be highly reusable.

To achieve this goal, we have made a little expansion of androidannotations, GitHub address: https://github.com/ChatGame/androidannotations

The practice of programming with MVP mode on Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.