本文整理匯總了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();
}
});
}