Reputation: 3262
I am reading about the Android Lifecycle from the Android Developers docs, and in the onPause()
part there is this following code snippet:
public class JavaCameraComponent implements LifecycleObserver {
...
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void releaseCamera() {
if (camera != null) {
camera.release();
camera = null;
}
}
...
}
Does it mean that there is an activity in the app that starts the camera, and this activity sends an ON_PAUSE
event to the life-cycle aware component, and only when it receives this event, it will start the camera? (Meaning that the sending activity is currently on paused state, because the camera app is running?)
Upvotes: 0
Views: 85
Reputation: 24907
Does it mean that there is an activity in the app that starts the camera, and this activity sends an ON_PAUSE event to the life-cycle aware component, and only when it receives this event, it will start the camera?
The code snippet you have provided doesn't mean that when you receive the Event.ON_PAUSE
, the camera will be started. What it means is, I'am done with camera usage and freeing up the camera for use by other applications.
and this activity sends an ON_PAUSE
No. These lifecycle events are dispatched from the framework and the Lifecycle class. These events map to the callback events in activities and fragments. You can refer the official documentation for more details
For the code you have added,it will simply release the camera on ON_PAUSE
event
Upvotes: 3