content: package com.dev.kit.basemodule.activity;
  
  import android.os.Bundle;
  import androidx.annotation.CallSuper;
  import androidx.annotation.NonNull;
  
  
  import com.trello.rxlifecycle4.LifecycleProvider;
  import com.trello.rxlifecycle4.LifecycleTransformer;
  import com.trello.rxlifecycle4.RxLifecycle;
  import com.trello.rxlifecycle4.android.ActivityEvent;
  import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
  
  import androidx.appcompat.app.AppCompatActivity;
  import io.reactivex.rxjava3.core.Observable;
  import io.reactivex.rxjava3.subjects.BehaviorSubject;
  
  
  /**
   * RxActivity
   * Created by cuiyan on 16/6/8.
   */
  public class RxActivity extends AppCompatActivity implements LifecycleProvider<ActivityEvent> {
  
      private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
  
      @Override
      @CallSuper
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          lifecycleSubject.onNext(ActivityEvent.CREATE);
      }
  
      @Override
      @CallSuper
      protected void onStart() {
          super.onStart();
          lifecycleSubject.onNext(ActivityEvent.START);
      }
  
      @Override
      @CallSuper
      protected void onResume() {
          super.onResume();
          lifecycleSubject.onNext(ActivityEvent.RESUME);
      }
  
      @Override
      @CallSuper
      protected void onPause() {
          super.onPause();
          // 防止activity 进入后台时解除绑定
  //        lifecycleSubject.onNext(ActivityEvent.PAUSE);
      }
  
      @Override
      @CallSuper
      protected void onStop() {
          super.onStop();
          lifecycleSubject.onNext(ActivityEvent.STOP);
      }
  
      @Override
      @CallSuper
      protected void onDestroy() {
          super.onDestroy();
          lifecycleSubject.onNext(ActivityEvent.DESTROY);
      }
  
  
  
  
      @NonNull
      @Override
      public Observable<ActivityEvent> lifecycle() {
          return lifecycleSubject.hide();
      }
  
      @NonNull
      @Override
      public <T> LifecycleTransformer<T> bindUntilEvent(@NonNull ActivityEvent event) {
          return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
      }
  
      @NonNull
      @Override
      public <T> LifecycleTransformer<T> bindToLifecycle() {
          return RxLifecycleAndroid.bindActivity(lifecycleSubject);
      }
  }
  