Mattiemus
Mattiemus

Reputation: 353

Android camera preview stops after unlocking phone

I am having an issue with an android project, our camera preview stops, however only after the phone has been locked then unlocked, it is also unable to take a photo, this issue has me genuinely stumped and I have been unable to find any information on this error around the internet and seem to be doing what all tutorials/other stack overflow questions state:

@Override
protected void onResume() { 
    super.onResume(); 
    mPreview.setVisibility(View.VISIBLE); 
    //Open the default i.e. the first rear facing camera. 
    mCamera = Camera.open(); 
    try{ 
         mCamera.reconnect(); 
    } catch(Exception ex) { 
    } 
    mCamera.startPreview(); 
    cameraCurrentlyLocked = defaultCameraId; 
    mPreview.setCamera(mCamera); 
} 

@Override 
protected void onPause() { 
    super.onPause(); 
    mPreview.setVisibility(View.GONE); 
    //Because the Camera object is a shared resource, it's very 
    //Important to release it when the activity is paused. 
    if (mCamera != null) { 
        mPreview.setCamera(null); 
        mCamera.stopPreview(); 
        mCamera.release(); 
        mCamera = null; 
    } 
} 

And the errors (on taking a photo) are as follows:

02-25 13:26:20.710: W/dalvikvm(17873): threadid=1: thread exiting with 
uncaught exception (group=0x41635450) 
02-25 13:26:20.710: E/AndroidRuntime(17873): FATAL EXCEPTION: main 
02-25 13:26:20.710: E/AndroidRuntime(17873): java.lang.IllegalStateException: 
Could not execute method of the activity 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.view.View$1.onClick(View.java:3671) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.view.View.performClick(View.java:4171) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.view.View$PerformClick.run(View.java:17195) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.os.Handler.handleCallback(Handler.java:643) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.os.Handler.dispatchMessage(Handler.java:92) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.os.Looper.loop(Looper.java:137) 
02-25 13:26:20.710: E/AndroidRuntime(17873): at 
android.app.ActivityThread.main(ActivityThread.java:4803) 

Any help is very appreciated.

Upvotes: 2

Views: 658

Answers (1)

baboo
baboo

Reputation: 2023

I was facing the same problem a few days ago ...Try: remove the preview from framelayout in onpause and add it again in onresume ..

Upvotes: 7

Related Questions