當前位置: 首頁>>代碼示例>>Java>>正文


Java Lifecycle.Event方法代碼示例

本文整理匯總了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();
    }
 
開發者ID:jzallas,項目名稱:LifecycleAware,代碼行數:17,代碼來源:LifecycleObserverGenerator.java

示例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();
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:19,代碼來源:RxLifecycleTest.java

示例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
    );
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:22,代碼來源:AndroidLifecycleActivityTest.java

示例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");
    }
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:20,代碼來源:RxLifecycleAndroidLifecycle.java

示例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
    );
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:22,代碼來源:AndroidLifecycleFragmentTest.java

示例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();
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:9,代碼來源:RxLifecycleTest.java

示例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);
        }
    });
}
 
開發者ID:florent37,項目名稱:RxComponentLifecycle,代碼行數:9,代碼來源:RxLifecycle.java

示例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();
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:33,代碼來源:RxLifecycleTest.java

示例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);
        }
    });
}
 
開發者ID:florent37,項目名稱:RxComponentLifecycle,代碼行數:9,代碼來源:RxLifecycle.java

示例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);
        }
    });
}
 
開發者ID:florent37,項目名稱:RxComponentLifecycle,代碼行數:9,代碼來源:RxLifecycle.java

示例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);
        }
    });
}
 
開發者ID:florent37,項目名稱:RxComponentLifecycle,代碼行數:9,代碼來源:RxLifecycle.java

示例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);
        }
    });
}
 
開發者ID:florent37,項目名稱:RxComponentLifecycle,代碼行數:9,代碼來源:RxLifecycle.java

示例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);
    }
}
 
開發者ID:xufreshman,項目名稱:RxLifeCycle,代碼行數:8,代碼來源:AndroidLifecycle.java

示例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());
}
 
開發者ID:jingle1267,項目名稱:AndroidArchitectureComponets,代碼行數:5,代碼來源:LocationListener.java

示例15: handleLifecycleEvent

import android.arch.lifecycle.Lifecycle; //導入方法依賴的package包/類
public void handleLifecycleEvent(final Lifecycle.Event event) {
	lifecycle.handleLifecycleEvent(event);
}
 
開發者ID:WaylonBrown,項目名稱:LifecycleAwareRx,代碼行數:4,代碼來源:LifecycleTest.java


注:本文中的android.arch.lifecycle.Lifecycle.Event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。