LifecycleObserver

2019-01-03  本文已影响0人  弘法大师

android.arch.lifecycle包提供了LifecycleObserver接口,方便我们直接绑定Activity或者是Fragment的生命周期

public class BaseActivityEventManager implements LifecycleObserver {

    private AppCompatActivity mActivity;


    public void register(AppCompatActivity activity) {
        mActivity = activity;
        mActivity.getLifecycle().addObserver(this);
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onResume() {

    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause() {
    }


    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
        release();
    }

    public void release() {

    }


 


}
上一篇下一篇

猜你喜欢

热点阅读