gpt4 book ai didi

Android 相机打开延迟 Activity 加载

转载 作者:行者123 更新时间:2023-11-29 14:48:29 32 4
gpt4 key购买 nike

我正在尝试使用 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com