@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)//绑定fragment的创建时刻 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)//绑定fragment的销毁时刻
其他可参考:
public enum Event { /** * Constant for onCreate event of the {@link LifecycleOwner}. */ ON_CREATE, /** * Constant for onStart event of the {@link LifecycleOwner}. */ ON_START, /** * Constant for onResume event of the {@link LifecycleOwner}. */ ON_RESUME, /** * Constant for onPause event of the {@link LifecycleOwner}. */ ON_PAUSE, /** * Constant for onStop event of the {@link LifecycleOwner}. */ ON_STOP, /** * Constant for onDestroy event of the {@link LifecycleOwner}. */ ON_DESTROY, /** * An {@link Event Event} constant that can be used to match all events. */ ON_ANY;
原文:https://www.cnblogs.com/--here--gold--you--want/p/15014327.html