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() {
}
}
网友评论