androidx.lifecycle.Lifecycle.removeObserver()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(512)

本文整理了Java中androidx.lifecycle.Lifecycle.removeObserver()方法的一些代码示例,展示了Lifecycle.removeObserver()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lifecycle.removeObserver()方法的具体详情如下:
包路径:androidx.lifecycle.Lifecycle
类名称:Lifecycle
方法名:removeObserver

Lifecycle.removeObserver介绍

[英]Removes the given observer from the observers list.

If this method is called while a state change is being dispatched,

  • If the given observer has not yet received that event, it will not receive it.
  • If the given observer has more than 1 method that observes the currently dispatched event and at least one of them received the event, all of them will receive the event and the removal will happen afterwards.
    [中]从“观察者”列表中删除给定的观察者。
    如果在分派状态更改时调用此方法,
    *如果给定的观察者尚未接收到该事件,它将不会接收该事件。
    *如果给定的观察者有多个方法来观察当前分派的事件,并且其中至少有一个接收到该事件,则所有观察者都将接收该事件,随后将进行删除。

代码示例

代码示例来源:origin: trello/RxLifecycle

@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);
    }
  }
}

代码示例来源:origin: chat-sdk/chat-sdk-android

public void setEnabled (boolean enabled) {
  if (enabled == this.enabled) {
    return;
  }
  this.enabled = enabled;
  if(enabled) {
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
  }
  else {
    ProcessLifecycleOwner.get().getLifecycle().removeObserver(this);
  }
}

代码示例来源:origin: skydoves/ColorPickerView

/**
 * removes this color picker observer from the the {@link LifecycleOwner}.
 *
 * @param lifecycleOwner {@link LifecycleOwner}.
 */
public void removeLifecycleOwner(LifecycleOwner lifecycleOwner) {
  lifecycleOwner.getLifecycle().removeObserver(this);
}

相关文章

微信公众号

最新文章

更多