美文网首页
LifecycleObserver

LifecycleObserver

作者: 弘法大师 | 来源:发表于2019-01-03 15:47 被阅读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() {
    
        }
    
    
     
    
    
    }
    

    相关文章

      网友评论

          本文标题:LifecycleObserver

          本文链接:https://www.haomeiwen.com/subject/tdafrqtx.html