Added ability clear lifecycleObserver

pull/798/head
alexander.melnikov 6 years ago
parent 778cdedc00
commit d25d5e52ce
  1. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -752,13 +752,24 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* Sets the lifecycle owner for this view. This means you don't need * Sets the lifecycle owner for this view. This means you don't need
* to call {@link #open()}, {@link #close()} or {@link #destroy()} at all. * to call {@link #open()}, {@link #close()} or {@link #destroy()} at all.
* *
* If you want that lifecycle stopped controlling the state of the camera,
* pass null in this method.
*
* @param owner the owner activity or fragment * @param owner the owner activity or fragment
*/ */
public void setLifecycleOwner(@NonNull LifecycleOwner owner) { public void setLifecycleOwner(@Nullable LifecycleOwner owner) {
if (mLifecycle != null) mLifecycle.removeObserver(this); if (owner == null) {
clearLifecycleObserver();
} else {
clearLifecycleObserver();
mLifecycle = owner.getLifecycle(); mLifecycle = owner.getLifecycle();
mLifecycle.addObserver(this); mLifecycle.addObserver(this);
} }
}
private void clearLifecycleObserver() {
if (mLifecycle != null) mLifecycle.removeObserver(this);
}
/** /**
* Starts the camera preview, if not started already. * Starts the camera preview, if not started already.

Loading…
Cancel
Save