android.arch.lifecycle.Lifecycle.Event Java Examples

The following examples show how to use android.arch.lifecycle.Lifecycle.Event. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LifecycleScope.java    From rxjava-RxLife with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateChanged(LifecycleOwner source, Event event) {
    if (event.equals(this.event)) {
        disposable.dispose();
        source.getLifecycle().removeObserver(this);
    }
}
 
Example #2
Source File: BaseScope.java    From rxjava-RxLife with Apache License 2.0 5 votes vote down vote up
@Override
public void onStateChanged(LifecycleOwner source, Event event) {
    //Activity/Fragment 生命周期回调
    if (event == Event.ON_DESTROY) {  //Activity/Fragment 销毁
        source.getLifecycle().removeObserver(this);
        dispose(); //中断RxJava管道
    }
}
 
Example #3
Source File: ConfigResistantObserver.java    From robocar with Apache License 2.0 5 votes vote down vote up
@OnLifecycleEvent(Event.ON_START)
public final void onStart() {
    mStartCount++;
    if (mStartCount == 1 && mStopSent) {
        mStopSent = false;
        onReallyStart();
    } else {
        mHandler.removeCallbacks(mDelayedStopRunnable);
    }
}
 
Example #4
Source File: ConfigResistantObserver.java    From robocar with Apache License 2.0 5 votes vote down vote up
@OnLifecycleEvent(Event.ON_STOP)
public final void onStop() {
    mStartCount--;
    if (mStartCount == 0) {
        mHandler.postDelayed(mDelayedStopRunnable, TIMEOUT_MS);
    }
}
 
Example #5
Source File: RxLife.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
public static <T> RxConverter<T> as(LifecycleOwner owner) {
    return as(owner, Event.ON_DESTROY, false);
}
 
Example #6
Source File: RxLife.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
public static <T> RxConverter<T> as(LifecycleOwner owner, Event event) {
    return as(owner, event, false);
}
 
Example #7
Source File: RxLife.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
public static <T> RxConverter<T> asOnMain(LifecycleOwner owner) {
    return as(owner, Event.ON_DESTROY, true);
}
 
Example #8
Source File: RxLife.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
public static <T> RxConverter<T> asOnMain(LifecycleOwner owner, Event event) {
    return as(owner, event, true);
}
 
Example #9
Source File: RxLife.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
private static <T> RxConverter<T> as(LifecycleOwner owner, Event event, boolean onMain) {
    return as(LifecycleScope.from(owner, event), onMain);
}
 
Example #10
Source File: LifecycleScope.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
private LifecycleScope(Lifecycle lifecycle, Event event) {
    this.lifecycle = lifecycle;
    this.event = event;
}
 
Example #11
Source File: LifecycleScope.java    From rxjava-RxLife with Apache License 2.0 4 votes vote down vote up
static LifecycleScope from(LifecycleOwner owner, Event event) {
    return new LifecycleScope(owner.getLifecycle(), event);
}
 
Example #12
Source File: Lantern.java    From lantern with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(Event.ON_DESTROY)
public void cleanup() {
    handler.removeCallbacks(pulseRunnable);
    displayLightController.cleanup();
    this.activityWeakRef = null;
}
 
Example #13
Source File: ConnectorFragment.java    From robocar with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(Event.ON_CREATE)
public void create() {
    mGoogleApiClient.registerConnectionCallbacks(ConnectorFragment.this);
    mGoogleApiClient.registerConnectionFailedListener(ConnectorFragment.this);
}
 
Example #14
Source File: ConnectorFragment.java    From robocar with Apache License 2.0 4 votes vote down vote up
@OnLifecycleEvent(Event.ON_DESTROY)
public void destroy() {
    mGoogleApiClient.unregisterConnectionCallbacks(ConnectorFragment.this);
    mGoogleApiClient.unregisterConnectionFailedListener(ConnectorFragment.this);
}