当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleObserver类代码示例

本文整理汇总了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();
}
 
开发者ID:skydoves,项目名称:Kickback,代码行数:17,代码来源:KickbackBoxGenerator.java

示例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);
            }
        });
    }
}
 
开发者ID:dasfoo,项目名称:delern,代码行数:33,代码来源:PerfEventTracker.java

示例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
}
 
开发者ID:Superingxz,项目名称:MoligyMvpArms,代码行数:13,代码来源:BasePresenter.java

示例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();
}
 
开发者ID:jzallas,项目名称:LifecycleAware,代码行数:9,代码来源:LifecycleObserverGenerator.java

示例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;
}
 
开发者ID:worldiety,项目名称:homunculus,代码行数:20,代码来源:ContextScope.java

示例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();
}
 
开发者ID:skydoves,项目名称:Kickback,代码行数:8,代码来源:KickbackBoxGenerator.java

示例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);
    }
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:11,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:12,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:14,代码来源:BaseFragment.java

示例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;
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:13,代码来源:BaseFragment.java

示例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);
    }
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:11,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:12,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:14,代码来源:BaseFragment.java

示例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;
}
 
开发者ID:xiaobailong24,项目名称:MVVMArms,代码行数:13,代码来源:BaseFragment.java

示例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();
        }
    });
}
 
开发者ID:dasfoo,项目名称:delern,代码行数:12,代码来源:AbstractActivity.java


注:本文中的android.arch.lifecycle.LifecycleObserver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。