Click here to Skip to main content
15,888,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am doing a project releated to livewallpaper, my app requirement is when the user Click the button camera preview set as wallpaper. i am doing all this stuff, but problem is after set the camera preview as wallpaper, when try to open the camera, it shows camera failed, i know we create only one camera object at a time, but problem was how to release the camera berfore the user use the camera in other applications and how to start camera preview in wallpaper after user close the camera application dynamically.
can any one give me an idea how can i do that?

Posted

When you start another Activity, your previous Activity will be paused. The onPause() method will be triggered. so what you should do:
@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		if (camera != null) {
			camera.stopPreview();
			camera.release();
			camera = null;
		}
	}
 
Share this answer
 
Comments
Somanadh B 8-Jan-14 0:05am    
thanks for reply, but i am not using camera in activity, i am using camera in wallpaper Engine class, so i did not know how to handle this, because user set camera as wallpaper then it runs continuously till the user did not open any camera applications, if user open the camera then service will be release that camera to reusable by other camera application, after camera application is closed, service will take the camera and continue the process. This is my app requirement.
I am using onvisibilitychange method in Wallpaper engine class,when this method returns false i relesing the camera, because of this other applications use the camera, but problem is when this method returns true it did not display the camera.
can you please give me an idea how to resolve this issue?
use the OnVisbilityChange() in Engine class to release the camera and start the camera.


@Override
C#
public void onVisibilityChanged(boolean visible) {
    // TODO Auto-generated method stub
    super.onVisibilityChanged(visible);
    if (visible) {
        try {
            //open the camera obj
        }catch(Exception e){
            e.printStackTrace();
        }

    }
    else {
        try {
            //release the camera obj
        }catch (RuntimeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900