Attention should be paid when using MVP for Android.

Source: Internet
Author: User

Attention should be paid when using MVP for Android.

  • Lifecycle:Because Presenter is created by View, we need to ensure that we fully understand the life cycle of View, especially because it will most likely process state update and asynchronous data. For example, each Presenter should cancel an asynchronous task in View destroyed, or reset it to the original state when the user pauses or restores the View event. Last but not least, when the View has been destroyed and you try to update the View element from the Presenter, always pay attention to the terrible NPEs.

  • Keep Views as stupid as possible:Our Views should no longer contain any business-related logic. It should only contain the minimum things of the Android framework inflate and set the View. Any user interaction should be distributed to the Presenter. Based on experience, if your views has any other method to update the UI elements or respond to user-triggered events, You may check their implementations.

  • Keep the Presenter as pure as possible:In this regard, you should try to avoid Android-related code in your presenters. Writing pure unit tests for these components without the need to use other testing frameworks such as Robolectric, which is obviously simplified. This is much easier to say than doing it, because you will eventually encounter this situation in some places. For example, you will need a reference of Context to load data and access strings files.

Related Article

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.