Giter Site home page Giter Site logo

nikan0925 / perfect-mvp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ljqloveyou123/perfect-mvp

0.0 0.0 0.0 142 KB

该库是一个对MVP模式的封装,主要目的解决MVP的内存泄露、代码冗余、Presenter的生命周期管理等问题

Java 100.00%

perfect-mvp's Introduction

该库是一个对MVP模式的封装,主要目的解决MVP的内存泄露、代码冗余、Presenter的生命周期管理等问题

如果你想知道为何最终这么封装的过程和思路,请看:

博客地址:http://blog.csdn.net/yulong0809/article/details/78622428

如果你不想知道的话,也可以直接下载perfect-mvp的Module直接使用,

使用方法:

  1. 在V层类上生命需要创建的Presenter注解,泛型中声明具体V层接口和Presenter类型,实现自己的V层接口 View接口必须继承BaseMvpView,Presenter必须继承BaseMvpPresenter,

    //声明需要创建的Presenter @CreatePresenter(RequestPresenter5.class) public class MainActivity extends AbstractMvpAppCompatActivity<RequestView5, RequestPresenter5> implements RequestView5 {

    。。。

    }

2.如何想通过自己的方法创建Presenter,必须在 调用onResume方法和getMvpPresenter方法之前设置,可以在onCreate方法中设置

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //设置自己的Presenter工厂,如果你想自定义的话
	// setPresenterFactory(xxx);

}

3.V层使用Presenter直接掉到getMvpPresenter()即可,Presenter中使用View可以直接调用getMvpView()即可

4.如果界面意外销毁,Presenter可以通过重写以下方法进行释放资源,存储数据,和恢复数据

/**
 * Presenter被创建后调用
 *
 * @param savedState 被意外销毁后重建后的Bundle
 */
public void onCreatePersenter(@Nullable Bundle savedState) {
}

/**
 * Presenter被销毁时调用
 */
public void onDestroyPersenter() {
}

/**
 * 在Presenter意外销毁的时候被调用,它的调用时机和Activity、Fragment、View中的onSaveInstanceState
 * 时机相同
 *
 * @param outState
 */
public void onSaveInstanceState(Bundle outState) {
}

perfect-mvp's People

Contributors

ljqloveyou123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.