在不同的过程中打开相机 [英] Opening the camera in a different process

查看:235
本文介绍了在不同的过程中打开相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个应用程式在某些 Kitkat Samsung 装置中发生严重的活动重建问题。这个问题在拍照时出现得更频繁,并且在一半的内存中没有观察到愁容的 Jellybean Samsung 。日志显示低内存条件,虽然没有 OutOfMemoryException 被抛出。我认为在 Kitkat 中有一个更积极的活动结束策略(或者默认的照相机应用程序是泄漏的)。

One of my apps has a serious activity recreation issue in some Kitkat Samsung devices. The problem appears more frequently when taking pictures, and it isn't observed in crappy Jellybean Samsungs with half the RAM. Logs show a low memory condition, although no OutOfMemoryExceptions are being thrown. I think there's a more aggressive activity closing policy in Kitkat (or else the default camera app is leaky).

我想知道当我的应用程序的内存较高时,操作系统是否关闭我的活动,或者当所有应用程序使用的总内存较高时,它关闭它。如果操作系统具有每进程的阈值,则可能在不同的进程中打开相机可能有帮助。

I was wondering whether the OS closes my activities when my app's memory is high, or instead it closes them when the total memory used by all apps is high. If the OS had a per-process threshold, then maybe opening the camera in a different process might help.

我知道可以在自己的进程中启动服务使用清单中的过程属性。假设 Activities 不存在等价属性,如果我在其自己的进程中启动了代理服务,然后从此服务启动了一个活动,该活动也会在该进程中运行吗?

I know it is possible to start a service in its own process using the process attribute in the manifest. Assuming no equivalent attribute exists for Activities, if I started a proxy service in its own process and then started an activity from this service, would the activity run in this process as well?

推荐答案

所描述的行为完全符合应用程序基础文档,它清楚地表明,在不同的过程中打开相机不会帮助你,只是因为这是默认情况下已经发生的:

The behaviour described is totally agreed with the Application fundamentals documentation from which it is clear that "opening the camera in a different process" won't help you, just because this is what already happens by default:


当系统启动一个组件时,它会启动该应用程序的进程并实例化组件所需的类。例如,如果您的应用在捕获照片的相机应用中启动活动,则该活动会在属于相机应用的过程中运行,而不是在您的应用进程中。

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.

所以当相机应用程序被带到前台,你的应用程序转到背景,这使它成为候选人之一被系统杀死时,内存低,因为流程和应用程序生命周期。你正在目睹一个正常的操作系统的行为。 RAM的总量不是关键点。

So when the camera app is brought to foreground, your app goes to background, which makes it be one of the candidates to be killed by the system when it is low on memory as per Processes and Application Life Cycle. You're witnessing a normal OS's behaviour. Total amount of RAM isn't a key point. Free memory of the amount available for the process in foreground matters.

这样说,你的问题的答案是。任何活动在其最初通过清单文件声明的应用程序(进程)中启动和运行,无论启动请求来自哪个进程。

With that said, the answer to your question is No. Any Activity starts and runs within the application (process) it was originally declared in through the manifest file, no matter which process the start request comes from.

命令

adb shell ps | grep 'app_name'

会告诉您您的相机应用程序正在运行。

will tell you which processes your and camera app are running on.

两个应用程序可以在同一个进程中运行,但是必要的先决条件是应用程序的相同签名...从应用程序基础

Two apps can run in the same process though, but the necessary prerequisite for this is the same signature of the apps... From Application fundamentals:


对于两个应用程序共享相同的Linux用户ID ...具有相同用户ID的应用程序也可以安排在相同的Linux进程中运行并共享同一个VM(应用程序也必须使用相同的证书签名)。

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

这篇关于在不同的过程中打开相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆