本文整理匯總了Java中android.arch.lifecycle.Lifecycle.Event方法的典型用法代碼示例。如果您正苦於以下問題:Java Lifecycle.Event方法的具體用法?Java Lifecycle.Event怎麽用?Java Lifecycle.Event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.arch.lifecycle.Lifecycle
的用法示例。
在下文中一共展示了Lifecycle.Event方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: defineLifecycleHook
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
private MethodSpec defineLifecycleHook() {
final String methodName = "onLifecycleEvent";
Lifecycle.Event lifecycleEvent = annotatedElement.getAnnotation(LifecycleAware.class).value();
AnnotationSpec archLifeCycleSpec = AnnotationSpec.builder(OnLifecycleEvent.class)
.addMember(ANNOT_DEFAULT_NAME, "$T.$L", Lifecycle.Event.class, lifecycleEvent)
.build();
return MethodSpec.methodBuilder(lifecycleEvent.name())
.addAnnotation(archLifeCycleSpec)
.addModifiers(Modifier.PUBLIC)
.addStatement("$L.$L($T.$L)", FIELD_OBSERVER, methodName, Lifecycle.Event.class, lifecycleEvent)
.build();
}
示例2: testBindUntilLifecycleEvent
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@Test
public void testBindUntilLifecycleEvent() {
BehaviorSubject<Lifecycle.Event> lifecycle = BehaviorSubject.create();
TestObserver<Object> testObserver =
observable.compose(RxLifecycle.bindUntilEvent(lifecycle, Lifecycle.Event.ON_STOP)).test();
lifecycle.onNext(Lifecycle.Event.ON_CREATE);
testObserver.assertNotComplete();
lifecycle.onNext(Lifecycle.Event.ON_START);
testObserver.assertNotComplete();
lifecycle.onNext(Lifecycle.Event.ON_RESUME);
testObserver.assertNotComplete();
lifecycle.onNext(Lifecycle.Event.ON_PAUSE);
testObserver.assertNotComplete();
lifecycle.onNext(Lifecycle.Event.ON_STOP);
testObserver.assertComplete();
}
示例3: testLifecycle
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
private void testLifecycle(ActivityController<? extends LifecycleOwner> controller) {
LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());
TestObserver<Lifecycle.Event> testObserver = provider.lifecycle().test();
controller.create();
controller.start();
controller.resume();
controller.pause();
controller.stop();
controller.destroy();
testObserver.assertValues(
Lifecycle.Event.ON_CREATE,
Lifecycle.Event.ON_START,
Lifecycle.Event.ON_RESUME,
Lifecycle.Event.ON_PAUSE,
Lifecycle.Event.ON_STOP,
Lifecycle.Event.ON_DESTROY
);
}
示例4: apply
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@Override
public Lifecycle.Event apply(Lifecycle.Event lastEvent) throws Exception {
switch (lastEvent) {
case ON_CREATE:
return Lifecycle.Event.ON_DESTROY;
case ON_START:
return Lifecycle.Event.ON_STOP;
case ON_RESUME:
return Lifecycle.Event.ON_PAUSE;
case ON_PAUSE:
return Lifecycle.Event.ON_STOP;
case ON_STOP:
return Lifecycle.Event.ON_DESTROY;
case ON_DESTROY:
throw new OutsideLifecycleException("Cannot bind to Activity lifecycle when outside of it.");
default:
throw new UnsupportedOperationException("Binding to " + lastEvent + " not yet implemented");
}
}
示例5: testLifecycle
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
private void testLifecycle(LifecycleOwner owner) {
Fragment fragment = (Fragment) owner;
ActivityController<?> controller = startFragment(fragment);
TestObserver<Lifecycle.Event> testObserver = AndroidLifecycle.createLifecycleProvider(owner).lifecycle().test();
controller.start();
controller.resume();
controller.pause();
controller.stop();
controller.destroy();
testObserver.assertValues(
Lifecycle.Event.ON_CREATE,
Lifecycle.Event.ON_START,
Lifecycle.Event.ON_RESUME,
Lifecycle.Event.ON_PAUSE,
Lifecycle.Event.ON_STOP,
Lifecycle.Event.ON_DESTROY
);
}
示例6: testEndsImmediatelyOutsideLifecycle
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@Test
public void testEndsImmediatelyOutsideLifecycle() {
BehaviorSubject<Lifecycle.Event> lifecycle = BehaviorSubject.create();
lifecycle.onNext(Lifecycle.Event.ON_DESTROY);
TestObserver<Object> testObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
testObserver.assertComplete();
}
示例7: onStart
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public Observable<Lifecycle.Event> onStart() {
return onEvent().filter(new Predicate<Lifecycle.Event>() {
@Override
public boolean test(@NonNull Lifecycle.Event event) throws Exception {
return ON_START.equals(event);
}
});
}
示例8: testBindLifecycle
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@Test
public void testBindLifecycle() {
BehaviorSubject<Lifecycle.Event> lifecycle = BehaviorSubject.create();
lifecycle.onNext(Lifecycle.Event.ON_CREATE);
TestObserver<Object> createObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
lifecycle.onNext(Lifecycle.Event.ON_START);
createObserver.assertNotComplete();
TestObserver<Object> startObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
lifecycle.onNext(Lifecycle.Event.ON_RESUME);
createObserver.assertNotComplete();
startObserver.assertNotComplete();
TestObserver<Object> resumeObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
lifecycle.onNext(Lifecycle.Event.ON_PAUSE);
createObserver.assertNotComplete();
startObserver.assertNotComplete();
resumeObserver.assertComplete();
TestObserver<Object> pauseObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
lifecycle.onNext(Lifecycle.Event.ON_STOP);
createObserver.assertNotComplete();
startObserver.assertComplete();
pauseObserver.assertComplete();
TestObserver<Object> stopObserver = observable.compose(RxLifecycleAndroidLifecycle.bindLifecycle(lifecycle)).test();
lifecycle.onNext(Lifecycle.Event.ON_DESTROY);
createObserver.assertComplete();
stopObserver.assertComplete();
}
示例9: onPause
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public Observable<Lifecycle.Event> onPause() {
return onEvent().filter(new Predicate<Lifecycle.Event>() {
@Override
public boolean test(@NonNull Lifecycle.Event event) throws Exception {
return ON_PAUSE.equals(event);
}
});
}
示例10: onStop
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public Observable<Lifecycle.Event> onStop() {
return onEvent().filter(new Predicate<Lifecycle.Event>() {
@Override
public boolean test(@NonNull Lifecycle.Event event) throws Exception {
return ON_STOP.equals(event);
}
});
}
示例11: onDestroy
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public Observable<Lifecycle.Event> onDestroy() {
return onEvent().filter(new Predicate<Lifecycle.Event>() {
@Override
public boolean test(@NonNull Lifecycle.Event event) throws Exception {
return ON_DESTROY.equals(event);
}
});
}
示例12: onAny
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public Observable<Lifecycle.Event> onAny() {
return onEvent().filter(new Predicate<Lifecycle.Event>() {
@Override
public boolean test(@NonNull Lifecycle.Event event) throws Exception {
return ON_ANY.equals(event);
}
});
}
示例13: onEvent
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onEvent(LifecycleOwner owner, Lifecycle.Event event) {
lifecycleSubject.onNext(event);
if (event == Lifecycle.Event.ON_DESTROY) {
owner.getLifecycle().removeObserver(this);
}
}
示例14: onAny
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onAny(LifecycleOwner owner, Lifecycle.Event event) {
Log.d("LifeCycleListener", "onAny:" + event.name());
}
示例15: handleLifecycleEvent
import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public void handleLifecycleEvent(final Lifecycle.Event event) {
lifecycle.handleLifecycleEvent(event);
}