android - 使用 camera.open() 时应用程序挂起/卡住 - 需要重启设备

标签 android camera freeze

我的应用程序非常基础和简单,我只需要打开相机(甚至不显示图像,我注释了代码)

所以,基本上,我有类似的东西:

@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");
    camera = Camera.open();
    Log.e("DebugCam", "After");
}

@Override
protected void onPause() {
    super.onPause();
    if (camera != null) {
        camera.stopPreview();
        camera.release();
        camera = null;
    }
}

但我的 logcat 只显示第一条消息:

Before

该应用只是挂起,我必须重新启动设备才能使其再次运行!!!

我真的不明白问题出在哪里,或者我怎样才能至少避免真正烦人的卡住。

我真的不知道如何调试它...

编辑:我在 Android 错误跟踪上看到了这个,听起来我需要一个解决方法,因为补丁已在 6 月发布) https://code.google.com/p/android/issues/detail?id=1578

最佳答案

我想总结一下我设法找到的有关该问题的所有信息。

我做了一些研究,我在 DroidForums 中发现了一个关于类似问题的有趣且可能没有那么紧密相关的线程。 :

在那里,他们发现是 SD 卡导致了卡住(我不确定现在是否是这种情况,但如果有人可以尝试就更好了),这是引述:

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..

一般来说,有时(或大多数情况下)似乎是存储卡导致了问题,所以如果您可以格式化您正在使用的存储卡或更换新存储卡,您就可以查看是否是问题所在问题。

此外,关于已记录的官方错误here (正如你提到的): 显然,测试用例与您在此处展示的相同,因为使用 Camera.open() 的应用程序在完全相同的地方遇到了问题。

引自那里:

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().

很高兴在最新版本中修复了此问题,几天前有评论(最后一条评论来自 2013 年 7 月 15 日):

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...)

希望我们能在这方面得到更新,所以让我们希望我们能在那里听到有关旧 API 的消息。

我进一步找到了线程 here (再次提及 SD 卡问题;信息不多,但无论如何):

引自那里:

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.

然后,有this thread在名为“4.2 Android camera APK FIX!”的 xda-Developers 上(不要兴奋,这仅适用于 ROOTED 设备:-( ):

从线程中获取的快速说明:

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

接下来(只是为了向广大公众提及),我在 AndroidCentral 中找到了这个,只是为了它,它又是根设备的“修复”。

在 sebertech 网站上,我发现了这个关于 Galaxy S3 相机问题的帖子,主要是 TouchWix - 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.

  1. 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.
  2. 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

  1. From the Home screen, press the Menu button and choose Settings.
  2. Scroll down to and tap on Developer Options.
  3. Find “Limit background processes” option and tap on it.
  4. Limit the Galaxy S3 to run about 4 processes at once, or lower.

Clear the data for TouchWiz

  1. From the Home screen, tap on Menu button.
  2. Choose System Settings then Application Manager
  3. 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.

最后,为了完成这个冗长的回答,我想说的是,尽管我发现了很少的修复/解决方法,但我真的希望 Official Bug Fix (再次链接,以便再次引用这个东西)将被广泛使用,不仅适用于 4.x.x 版本的 Android,遗憾的是我们没有旧版本(与旧 API 的错误修复?)。

关于android - 使用 camera.open() 时应用程序挂起/卡住 - 需要重启设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17655068/

相关文章:

android - 使用 adb shell android 打开或查看 .txt 的内容

android - WebView、类型文件、相机和图像的输入

ios - 跟踪相机的位置和旋转

c# - Parallel.For 在大约 1370 次迭代后卡住,不知道为什么

google-chrome - HTML5音频 “preload=” none“弄乱了pause()和currentTime()

android - 如何处理 Android JUnit 测试中的日志记录?

安卓软键盘隐藏分割条

android - faSTLane/supply dynamic 新功能(变更日志)

ios - 如何使用 Objective-C 以 120 fps 或 240 fps 录制视频

mysql - 保存到数据库,同时保持 UI 响应 VB.NET