From 95e3c0269f4eefd3f86b5a23c84ac80deb5d0508 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Fri, 14 Sep 2018 12:37:06 -0300 Subject: [PATCH] Add README info --- README.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a78546d7..4ed5ae16 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,21 @@ To use the CameraView engine, simply add a `CameraView` to your layout: android:layout_height="wrap_content" /> ``` -`CameraView` has lots of XML attributes, so keep reading. Make sure you override `onResume`, -`onPause` and `onDestroy` in your activity or fragment, and call `CameraView.start()`, `stop()` +`CameraView` is a component bound to your activity or fragment lifecycle. This means that you must pass the +lifecycle owner using `setLifecycleOwner`: + +```java +@Override +protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + CameraView camera = findViewById(R.id.camera); + camera.setLifecycleOwner(this); + // From fragments, use fragment.viewLifecycleOwner instead of this! +} +``` + +For those who are not using the support libraries and the lifecycle implementation, make sure you override `onResume`, +`onPause` and `onDestroy` in your component, and call `CameraView.start()`, `stop()` and `destroy()`. ```java