gpt4 book ai didi

android - 在不同的过程中打开相机

转载 作者:IT王子 更新时间:2023-10-28 23:32:52 26 4
gpt4 key购买 nike

我的一个应用在某些 Kitkat Samsung 设备中存在严重的 Activity 重新播放问题。该问题在拍照时出现的频率更高,并且在只有一半 RAM 的蹩脚 Jellybean Samsung 中没有观察到。日志显示内存不足,但没有抛出 OutOfMemoryException。我认为 Kitkat 中有更激进的 Activity 关闭策略(否则默认的相机应用程序会泄漏)。

我想知道操作系统是在我的应用程序的内存很高时关闭我的 Activity ,还是在所有应用程序使用的总内存很高时关闭它们。如果操作系统有每个进程的阈值,那么在不同的进程中打开相机可能会有所帮助。

我知道可以使用 list 中的 process 属性在自己的进程中启动服务。假设 Activities 不存在等效属性,如果我在自己的进程中启动代理服务,然后从该服务启动 Activity,那么该 Activity 是否也会在该进程中运行?

最佳答案

所描述的行为与Application fundamentals 完全一致。很明显“在不同的进程中打开相机”对你没有帮助的文档,因为这是默认情况下已经发生的事情:

When the system starts a component, it starts the process for that app (if it's not already running) and instantiates the classes needed for the component. For example, if your app starts the activity in the camera app that captures a photo, that activity runs in the process that belongs to the camera app, not in your app's process.

因此,当相机应用程序被带到前台时,您的应用程序会进入后台,这使得它成为根据 Processes and Application Life Cycle 内存不足时被系统杀死的候选者之一.您正在目睹正常操作系统的行为。 RAM 总量不是关键点。可用于前台进程的可用内存量。

话虽如此,您的问题的答案是。任何 Activity 在最初通过 list 文件声明的应用程序(进程)内启动和运行,无论启动请求来自哪个进程。

命令

adb shell ps | grep 'app_name'

会告诉您您的应用和相机应用正在哪些进程上运行。

虽然两个应用程序可以在同一个进程中运行,但必要的先决条件是应用程序的签名相同...来自 Application fundamentals :

It's possible to arrange for two apps to share the same Linux user ID... Apps with the same user ID can also arrange to run in the same Linux process and share the same VM (the apps must also be signed with the same certificate).

关于android - 在不同的过程中打开相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343779/

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