其他分享
首页 > 其他分享> > 2-2、Lifcycle核心接口

2-2、Lifcycle核心接口

作者:互联网

原文链接

1、LifecycleObserver 观察者

package androidx.lifecycle;


@SuppressWarnings("WeakerAccess")
public interface LifecycleObserver {

}

FullLifecycleObserver

interface FullLifecycleObserver extends LifecycleObserver {

    void onCreate(LifecycleOwner owner);

    void onStart(LifecycleOwner owner);

    void onResume(LifecycleOwner owner);

    void onPause(LifecycleOwner owner);

    void onStop(LifecycleOwner owner);

    void onDestroy(LifecycleOwner owner);
}

2、LifecycleOwner 被观察者

public interface LifecycleOwner {
    /**
     * Returns the Lifecycle of the provider.
     *
     * @return The lifecycle of the provider.
     */
    @NonNull
    Lifecycle getLifecycle();
}

Activity

public class ComponentActivity extends Activity
        implements LifecycleOwner, KeyEventDispatcher.Component {
        
		private final LifecycleRegistry mLifecycleRegistry = new LifecycleRegistry(this);
 
    @Override
    public Lifecycle getLifecycle() {
        return mLifecycleRegistry;
    }
}

Fragment

public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener, 		    LifecycleOwner, ViewModelStoreOwner {
  
    @Override
    public Lifecycle getLifecycle() {
        return mLifecycleRegistry;
    }
}

service

package androidx.lifecycle;
public class LifecycleService extends Service implements LifecycleOwner {

}

标签:LifecycleOwner,核心,void,接口,Lifecycle,Lifcycle,owner,public
来源: https://www.cnblogs.com/ArthurWangWang/p/14970166.html