本文整理汇总了Java中android.arch.lifecycle.LifecycleObserver类的典型用法代码示例。如果您正苦于以下问题:Java LifecycleObserver类的具体用法?Java LifecycleObserver怎么用?Java LifecycleObserver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LifecycleObserver类属于android.arch.lifecycle包,在下文中一共展示了LifecycleObserver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
public TypeSpec generate() {
return TypeSpec.classBuilder(getClassName())
.addJavadoc("Generated by Kickback. (https://github.com/skydoves/Kickback).\n")
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(LifecycleObserver.class)
.addFields(getKickbackFields())
.addMethods(getSetterMethodSpecs())
.addMethods(getGetterMethodSpecs())
.addMethods(getFreeMethodSpecs())
.addMethod(getBoxNameSpec())
.addMethods(getElementNameListSpecs())
.addMethod(getFreeAllSpec())
.addMethod(setLifecycleObserverSpec())
.addMethod(getLifecycleObserverSpec())
.build();
}
示例2: trackEventStart
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
/**
* Like {@link #trackEvent(Event, Context, Bundle)}, but also starts a performance Trace.
*
* @param event {@link #trackEvent(Event, Context, Bundle)}
* @param context {@link #trackEvent(Event, Context, Bundle)}
* @param bundle {@link #trackEvent(Event, Context, Bundle)}
* @param container lifecycle to attach Trace to (onDestroy will stop the trace).
*/
public static void trackEventStart(@NonNull final Event event, @NonNull final Context context,
@Nullable final Bundle bundle,
@Nullable final LifecycleOwner container) {
trackEvent(event, context, bundle);
if (sRunningEvents.containsKey(event)) {
LOGGER.error("Event {} triggered while performance counting for it was already in " +
"progress! Finishing now", event, new Throwable());
trackEventFinish(event);
}
Trace t = FirebasePerformance.startTrace(event.track());
sRunningEvents.put(event, t);
t.start();
if (container != null) {
// Container can be null if we test cross-activity lifecycle
container.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void stopTrace() {
trackEventFinish(event);
}
});
}
}
示例3: onStart
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
public void onStart() {
//将 LifecycleObserver 注册给 LifecycleOwner 后 @OnLifecycleEvent 才可以正常使用
if (mRootView != null && mRootView instanceof LifecycleOwner) {
((LifecycleOwner) mRootView).getLifecycle().addObserver(this);
if (mModel!= null && mModel instanceof LifecycleObserver){
((LifecycleOwner) mRootView).getLifecycle().addObserver((LifecycleObserver) mModel);
}
}
if (useEventBus())//如果要使用 Eventbus 请将此方法返回 true
EventBus.getDefault().register(this);//注册 Eventbus
}
示例4: defineClass
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
public TypeSpec defineClass() {
return TypeSpec.classBuilder(producer.getClassName(annotatedElement))
.addSuperinterface(LifecycleObserver.class)
.addField(LifecycleAwareObserver.class, FIELD_OBSERVER, Modifier.PRIVATE)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.build();
}
示例5: createScope
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
/**
* Creates a new scope for the given lifecycle owner (e.g. a Fragment or an Activity).
* Note: The lifetime is
* attached to the {@link android.arch.lifecycle.Lifecycle} AND the parent scope. So the returned
* scope is destroyed if either of them is destroyed.
*/
public static Scope createScope(@Nullable Scope parent, LifecycleOwner lifecycleOwner) {
Scope scope = new Scope(lifecycleOwner.toString(), parent);
lifecycleOwner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Event.ON_DESTROY)
void onDestroy() {
scope.destroy();
}
});
if (lifecycleOwner instanceof Context) {
scope.put(Android.NAME_CONTEXT, lifecycleOwner);
}
return scope;
}
示例6: getLifecycleObserverSpec
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
private MethodSpec getLifecycleObserverSpec() {
return MethodSpec.methodBuilder("getLifecycleObserver")
.addModifiers(Modifier.PUBLIC)
.returns(LifecycleObserver.class)
.addStatement("return this")
.build();
}
示例7: onCreate
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set the DataBinding
mBinding = DataBindingUtil.setContentView(this, initView(savedInstanceState));
initData(savedInstanceState);
if (mViewModel != null) {
getLifecycle().addObserver((LifecycleObserver) mViewModel);
}
}
示例8: onDestroy
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
protected void onDestroy() {
super.onDestroy();
this.mBinding = null;
this.mViewModelFactory = null;
//Removed LifecycleObserver
if (mViewModel != null) {
getLifecycle().removeObserver((LifecycleObserver) mViewModel);
}
this.mViewModel = null;
}
示例9: onCreateView
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRootView = initView(inflater, container, savedInstanceState);
if (mViewModel != null) {
getLifecycle().addObserver((LifecycleObserver) mViewModel);
}
//Visible, and is the first time to load
if (mVisible && mFirst) {
onFragmentVisibleChange(true);
}
return mRootView;
}
示例10: onDestroy
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
public void onDestroy() {
super.onDestroy();
this.mBinding = null;
this.mRootView = null;
this.mViewModelFactory = null;
//Removed LifecycleObserver
if (mViewModel != null) {
getLifecycle().removeObserver((LifecycleObserver) mViewModel);
}
this.mViewModel = null;
}
示例11: onCreate
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置DataBinding
mBinding = DataBindingUtil.setContentView(this, initView(savedInstanceState));
initData(savedInstanceState);
if (mViewModel != null) {
getLifecycle().addObserver((LifecycleObserver) mViewModel);
}
}
示例12: onDestroy
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
protected void onDestroy() {
super.onDestroy();
this.mBinding = null;
this.mViewModelFactory = null;
//移除LifecycleObserver
if (mViewModel != null) {
getLifecycle().removeObserver((LifecycleObserver) mViewModel);
}
this.mViewModel = null;
}
示例13: onCreateView
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mRootView = initView(inflater, container, savedInstanceState);
if (mViewModel != null) {
getLifecycle().addObserver((LifecycleObserver) mViewModel);
}
//可见,并且是首次加载
if (mVisible && mFirst) {
onFragmentVisibleChange(true);
}
return mRootView;
}
示例14: onDestroy
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
public void onDestroy() {
super.onDestroy();
this.mBinding = null;
this.mRootView = null;
this.mViewModelFactory = null;
//移除LifecycleObserver
if (mViewModel != null) {
getLifecycle().removeObserver((LifecycleObserver) mViewModel);
}
this.mViewModel = null;
}
示例15: onCreate
import android.arch.lifecycle.LifecycleObserver; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void cleanDisposables() {
getLifecycle().removeObserver(this);
mDisposeOnDestroy.dispose();
}
});
}