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

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

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

Lifecycle.getCurrentState介绍

[英]Returns the current state of the Lifecycle.
[中]返回生命周期的当前状态。

代码示例

代码示例来源:origin: bluelinelabs/Conductor

@OnLifecycleEvent(Event.ON_ANY)
  void onLifecycleEvent(@NonNull LifecycleOwner source, @NonNull Event event) {
    Log.d(TAG, "Lifecycle: " + source.getClass().getSimpleName() + " emitted event " + event + " and is now in state " + source.getLifecycle().getCurrentState());
  }
});

代码示例来源:origin: bluelinelabs/Conductor

public ArchLifecycleController() {
  Log.i(TAG, "Conductor: Constructor called");
  getLifecycle().addObserver(new LifecycleObserver() {
    @OnLifecycleEvent(Event.ON_ANY)
    void onLifecycleEvent(@NonNull LifecycleOwner source, @NonNull Event event) {
      Log.d(TAG, "Lifecycle: " + source.getClass().getSimpleName() + " emitted event " + event + " and is now in state " + source.getLifecycle().getCurrentState());
    }
  });
  Log.d(TAG, "Lifecycle: " + getClass().getSimpleName() + " is now in state " + getLifecycle().getCurrentState());
}

代码示例来源:origin: ankidroid/Anki-Android

@Override
protected void onPostExecute(Collection col) {
  super.onPostExecute(col);
  if (mLifecycleOwner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.CREATED)) {
    mCallback.execute(col);
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void launch_lifecycleOwnerActivity() {
 ActivityScenario<LifecycleOwnerActivity> activityScenario =
   ActivityScenario.launch(LifecycleOwnerActivity.class);
 assertThat(activityScenario).isNotNull();
 activityScenario.onActivity(
   activity -> {
    assertThat(activity.getLifecycle().getCurrentState()).isEqualTo(State.RESUMED);
   });
 activityScenario.moveToState(State.STARTED);
 activityScenario.onActivity(
   activity -> {
    assertThat(activity.getLifecycle().getCurrentState()).isEqualTo(State.STARTED);
   });
 activityScenario.moveToState(State.CREATED);
 activityScenario.onActivity(
   activity -> {
    assertThat(activity.getLifecycle().getCurrentState()).isEqualTo(State.CREATED);
   });
}

代码示例来源:origin: zhiwei1990/android-jetpack-demo

public void enable() {
  enable = true;
  if (owner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
    //判断,如果没有开始定位,就再次开启定位,定位成功,使用callback回调UI刷新
    callBack.onSuccess();
  }
}

代码示例来源:origin: hazems/mvvm-sample-app

@Override
  public void onClick(Project project) {
    if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
      ((MainActivity) getActivity()).show(project);
    }
  }
};

代码示例来源:origin: xcesco/kripton

public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<? super T> observer) {
  assertMainThread("observe");
  if (owner.getLifecycle().getCurrentState() == DESTROYED) {

相关文章