Is there any way to release a camera from different activity after acquiring it from a different activity.?
android, camera, flashlight, java
Solution
Other answers have told you not to do this and why. But to answer your question:
Keep a reference to the `Camera` instance in a static member variable, preferably in a separate class, like this:
public class Globals {
public static Camera myCamera;
}
This variable is available to all of your activities as `Globals.myCamera`.
Put the instance of `Camera` that you get from calling `Camera.open()` into `Globals.myCamera`. This will be available to both activities. When you are ready to release the camera, call `Globals.myCamera.release()` and then set `Globals.myCamera` to `null` to indicate that you no longer have control of the camera.
Problem
I am developing a flashlight App in which there is a normal flashlight in one activity and strobe light in one activity. Now I am acquiring the camera in onCreate of Flashlight activity. But when I am oving to strobe activity, i need to release the camera acquired by FlashLight activity. I dont want to release the camera in onPause of FlashLight activity because that would stop the camera even if user presses the home button. I want to release the camera only when user goes to strobe activity or else he exits the app by back button. Also I want to reacquire the camera if the user is coming back to flashlight activity from strobe activity. Is their anyway to do this.?