Android 相机打开延迟 Activity 加载

标签 android android-camera

我正在尝试使用 SurfaceView 打开摄像头和显示。这会延迟 Activity 的加载很长时间。所以我想知道打开相机的最佳做法是什么。

最佳答案

来自 http://developer.android.com/training/camera/cameradirect.html :

Getting an instance of the Camera object is the first step in the process of directly controlling the camera. As Android's own Camera application does, the recommended way to access the camera is to open Camera on a separate thread that's launched from onCreate(). This approach is a good idea since it can take a while and might bog down the UI thread. In a more basic implementation, opening the camera can be deferred to the onResume() method to facilitate code reuse and keep the flow of control simple.

所以官方推荐使用独立线程。这将意味着修改 Activity 以能够处理相机尚未打开甚至可能无法完全打开的状态。

如果您不熟悉多线程和 Android 应用程序开发,最好让 Activity 停止运行。在大多数设备上,相机打开的速度非常快。

关于Android 相机打开延迟 Activity 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139292/

相关文章:

android - Android 自动对焦后的视频录制问题

android - FOREIGN KEY 约束失败(代码 787)[NO ANDROID ROOM]

android - 如何使 Android 中的 AlertDialog 超时?

android - Dropbox accesstoken 是否过期?我可以使用 Android Core API 自动登录 Dropbox 并获取新的 accesstoken 吗?

android - Libstreaming 错误(解码器缓冲区不够大,解码器没有解码任何东西)

java - 在android中将图片发送到网络服务器时出错

android - 将 gridview 项目可检查状态传播给 child

java - 在内部存储的文件夹内创建文件

Android - 减少相机上的眩光(照片/视频)

android - 使用 android.hardware.camera2 设置自定义分辨率和帧率