本文整理了Java中android.arch.lifecycle.Lifecycle.removeObserver()
方法的一些代码示例,展示了Lifecycle.removeObserver()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lifecycle.removeObserver()
方法的具体详情如下:
包路径:android.arch.lifecycle.Lifecycle
类名称:Lifecycle
方法名:removeObserver
[英]Removes the given observer from the observers list.
If this method is called while a state change is being dispatched,
代码示例来源:origin: JessYanCoding/MVPArms
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
void onDestroy(LifecycleOwner owner) {
owner.getLifecycle().removeObserver(this);
}
}
代码示例来源:origin: JessYanCoding/MVPArms
/**
* 只有当 {@code mRootView} 不为 null, 并且 {@code mRootView} 实现了 {@link LifecycleOwner} 时, 此方法才会被调用
* 所以当您想在 {@link Service} 以及一些自定义 {@link View} 或自定义类中使用 {@code Presenter} 时
* 您也将不能继续使用 {@link OnLifecycleEvent} 绑定生命周期
*
* @param owner link {@link SupportActivity} and {@link Fragment}
*/
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
void onDestroy(LifecycleOwner owner) {
/**
* 注意, 如果在这里调用了 {@link #onDestroy()} 方法, 会出现某些地方引用 {@code mModel} 或 {@code mRootView} 为 null 的情况
* 比如在 {@link RxLifecycle} 终止 {@link Observable} 时, 在 {@link io.reactivex.Observable#doFinally(Action)} 中却引用了 {@code mRootView} 做一些释放资源的操作, 此时会空指针
* 或者如果你声明了多个 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 时在其他 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
* 中引用了 {@code mModel} 或 {@code mRootView} 也可能会出现此情况
*/
owner.getLifecycle().removeObserver(this);
}
代码示例来源:origin: M66B/XPrivacyLua
void stopObserving() {
if (this.owner != null && this.dialog != null) {
owner.getLifecycle().removeObserver(this);
this.dialog = null;
}
}
代码示例来源:origin: SilenceDut/TaskScheduler
@Override
public void onStateChanged(LifecycleOwner source, Lifecycle.Event event) {
if(event == targetEvent) {
if(mLifecycleOwner!=null ) {
mLifecycleOwner.getLifecycle().removeObserver(this);
}
handler.removeCallbacks(LifecycleRunnableDelegate.this);
}
}
};
代码示例来源:origin: SilenceDut/TaskScheduler
@Override
public void run() {
if(mOriginRunnable!=null && mLifecycleOwner!=null) {
mOriginRunnable.run();
mLifecycleOwner.getLifecycle().removeObserver(mLifecycleObserver);
}
}
}
代码示例来源:origin: XunMengWinter/Now
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDisPose() {
// Logger.t(TAG).i("dispose");
if (mLifecycle != null)
mLifecycle.removeObserver(this);
if (mDisposable != null && !mDisposable.isDisposed())
mDisposable.dispose();
}
代码示例来源:origin: XunMengWinter/Now
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void destroy() {
print();
mLifecycle.removeObserver(this);
}
代码示例来源:origin: JessYanCoding/MVPArt
/**
* 只有当 {@code view} 实现了 {@link LifecycleOwner} 时, 此方法才会被调用
* 所以当您想在 {@link Service} 以及一些自定义 {@link View} 或自定义类中使用 {@code Presenter} 时
* 您也将不能继续使用 {@link OnLifecycleEvent} 绑定生命周期
*
* @param owner link {@link SupportActivity} and {@link Fragment}
*/
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
void onDestroy(LifecycleOwner owner) {
/**
* 注意, 如果在这里调用了 {@link #onDestroy()} 方法, 会出现某些地方引用 {@code mModel} 为 null 的情况
* 比如如果你声明了多个 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) 时在其他 @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
* 中引用了 {@code mModel} 也可能会出现此情况
*/
owner.getLifecycle().removeObserver(this);
}
代码示例来源:origin: listenzz/AndroidNavigation
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onStateChange() {
if (getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
tasks.clear();
getLifecycle().removeObserver(this);
} else {
considerExecute();
}
}
代码示例来源:origin: WaylonBrown/LifecycleAwareRx
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
void onStateChange() {
if (lifecycleOwner != null && lifecycleOwner.getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
// No memory leaks please
lifecycleOwner.getLifecycle().removeObserver(this);
lifecycleOwner = null;
}
}
}
代码示例来源:origin: smartdevicelink/sdl_android
@Override
public void dispose(){
// send broadcast to close lock screen if open
if (context.get() != null) {
context.get().sendBroadcast(new Intent(SDLLockScreenActivity.CLOSE_LOCK_SCREEN_ACTION));
}
// remove listeners
internalInterface.removeOnRPCNotificationListener(FunctionID.ON_HMI_STATUS, hmiListener);
internalInterface.removeOnRPCNotificationListener(FunctionID.ON_DRIVER_DISTRACTION, ddListener);
if (deviceLogoEnabled) {
internalInterface.removeOnRPCNotificationListener(FunctionID.ON_SYSTEM_REQUEST, systemRequestListener);
}
deviceLogo = null;
deviceIconUrl = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
if (android.arch.lifecycle.ProcessLifecycleOwner.get() != null && lifecycleObserver != null) {
android.arch.lifecycle.ProcessLifecycleOwner.get().getLifecycle().removeObserver(lifecycleObserver);
}
} catch (Exception e) {
e.printStackTrace();
}
lifecycleObserver = null;
}
isApplicationForegrounded = false;
super.dispose();
}
代码示例来源:origin: WaylonBrown/LifecycleAwareRx
/**
* Decides whether the stream needs to be destroyed or subscribed to.
*/
private void handleCurrentLifecycleState() {
if (lifecycleOwner != null &&
lifecycleOwner.getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
// No memory leaks please
this.lifecycleOwner.getLifecycle().removeObserver(this);
this.lifecycleOwner = null;
this.baseReactiveType = null;
} else if (LifecycleUtil.isInActiveState(lifecycleOwner)
&& !subscribed
&& baseReactiveType != null) {
// Subscribe to stream with observer since the LifecycleOwner is now active but wasn't previously
baseReactiveType.subscribeWithObserver();
subscribed = true;
}
}
内容来源于网络,如有侵权,请联系作者删除!