Application hangs / freeze when using camera.open() - Restart of device needed
I wanted to summarize all the information on the issue that I managed to find.
I've done some research and I found an interesting and probably not so tightly related thread about a similar problem in the DroidForums:
There they found out, that the SD card was causing the freeze (I'm not sure if that's the case now, but it will be good if someone can try it) and here's the quote from there:
My camera and camcorder were freezing up like many other people's and i was frustrated..in my hands i have my "Like-New" phone hoping that would help...no such luck...figured out what it was...THE SDHC CARD! simple format of the card and issues went away..to test this yourself go to your main settings and unmount the sd card and then restart the camera app and see if it doesnt freeze...if it doesnt like mine didnt then you have your answer...not exactly sure what on my SDHC card caused this...still under investigation, but definitely something there...i will update when i find out exactly what for everyone else
Hope this helps and thanks to all for the many tips I have used from this forum...
UPDATE!!!
I just had the same issue happen again with my new Gingerbread phone and I tried something new...just move some photos and vidoes off of the phone and back them up to PC...worked like a charm...no need to format entire card, just give the camera/ camcorder app some space..as if 5.5GB wasn't enough, but hey who knew...now videos only take 1/2 second to save and camera is working fine again...just thought i would let all of you know..
In general, it seems that the memory card is causing the problem sometimes (or in most of the cases), so if you can format the one you're using or replace it with a new one you can see if that's the issue.
Further, on the official bug, which was logged here (as you mentioned):
Apparently the test case is the same as the one you have presented here, as the applications which use Camera.open()
are experiencing the problem on the exact same place.
Quote from there:
Apparently, Camera.open() itself hangs without causing any exception, such that there is nothing that I can trap and act upon. I can then also not use the built-in camera app, as it gives just a black preview screen and a bit later a message about being unresponsive when I try to interact with it. Since in the above code snippet was already null (at program startup), there is just nothing that I can release: no camera.release().
It's good that this was fixed in the latest release and several days ago there was a comment (the last one, which is from Jul 15, 2013):
Thanks for the bugfixe, but is there a workaround for device older than 22 June 2013, when the patch was released (wich means after 4.2.2 released in february 2013...)
Hopefully we'll get updated on this one, so let's wish we're going to hear news there for older APIs.
Further I found the thread here (again, mentioning an SD card problem; not much info there, but anyway):
Quote from there:
And the solution found: I deleted the thumbnails on the image folder of my SD card and restarted the phone. It seems that the little thumbnail window which indicates the last shot was responsible for the app crash, for some reason the thumbs was unable to load and the application was crashing.
Then, there was this thread on the xda-Developers named "4.2 Android camera APK FIX!" (don't get excited, this is for ROOTED devices only :-( ):
Quick instructions taken from the thread:
Camera apk: http://db.tt/xmpgkZIA
Add this apk to system/app after installing camera apk first only for manual. http://db.tt/OZF6D8fL
This are the lib files place them on system/lib fix permission then reboot. http://db.tt/73lcCrcl http://db.tt/wQ7bfR8N
For those with device not supported, change the following lines in build.prop and reboot:
ro.product.model=Galaxy Nexus ro.product.brand=google
Next (just to mention it to the broad public), I found this in the AndroidCentral, just for the sake of it, it's again a "fix" for rooted devices.
On the website sebertech, I found this thread regarding a camera problem with Galaxy S3 and it's TouchWix mainly - LINK:
For Galaxy S3 units that are plagued with performance problems, rooting is the first step to resolving those issues. But you have to take into consideration the risks involved, although there are already safe ways to root the phone. But before you actually decide to do that, I have some things I want you to try.
- Recall apps that you’ve recently installed, try to disable them and see if there are improvements in the performance of your phone. Some really heavy apps may have even caused or contributed to the problem.
- Try clearing the memory by going to the Home screen and holding on the Home button. A list of running or recently opened apps will show; you just have to swipe left or right to close them. I’m pretty sure you already knew the effects of having so many apps running in the background.
Limit Galaxy S3 Processes
- From the Home screen, press the Menu button and choose Settings.
- Scroll down to and tap on Developer Options.
- Find “Limit background processes” option and tap on it.
- Limit the Galaxy S3 to run about 4 processes at once, or lower.
Clear the data for TouchWiz
- From the Home screen, tap on Menu button.
- Choose System Settings then Application Manager
- Scroll down to find TW and tap Clear Data.
If nothing else works, perhaps it’s time to root your device and use lighter and faster custom ROMs and get rid of the TouchWiz UI.
Finally, to finish this long answer I would like to say that, even though I found very few fixes/workarounds for this, I really hope, that the Official Bug Fix (linked again, in order to have this thing quoted once more) is going to be broadly available and not only for 4.x.x versions of Android, it's a pity that we don't have it for older versions (what's the deal with a bug fix for older APIs anyway?).
I faced a similar problem and this worked for me:
Apparently this call back was choking the buffers with the data for each frame of the camera preview.
camera.setPreviewCallback(new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera arg1) {
//invalidate surfaceview
}
});
Removing the callback worked for me. Hope it helps. :)
try this :
@Override
public void onResume() {
super.onResume();
if (camera != null) {
//Just to be sure
camera.stopPreview();
camera.setPreviewCallback(null);
camera.release();
camera = null;
}
Log.e("DebugCam", "Before");
try {
camera = Camera.open();// this is no safe way to open the camera
}catch(Exception e)
{
e.printStackTrace();//get the exception on Logcat
}
Log.e("DebugCam", "After");
}
Direct from DOCS
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
}
catch (Exception e){
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
Look this: http://developer.android.com/guide/topics/media/camera.html#custom-camera