Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening the camera in a different process

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.

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?

like image 632
Mister Smith Avatar asked Feb 11 '16 15:02

Mister Smith


People also ask

Could not open camera device could be used by another process?

Changing your camera privacy setting is an easy way to fix this issue. If you face another application using your camera error, it might be because of an outdated driver. You may need to update your Microsoft Store apps or disable the firewall to fix this error.

Why camera is not opening?

Check the Permissions of the Camera App Here's how to check whether you've mistakenly denied the permission and turn it on: Open the Settings app. Scroll down and tap App management > Permission manager. Select Camera and change the setting to Allow if it's disabled.

What is the permission for using the camera?

Getting Consent On Android Requesting camera permission on Android requires that you place a <uses-permission/> element in your app manifest. Camera access is a "dangerous permission" and thus you must obtain explicit consent before accessing it.


1 Answers

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.

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.

The command

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:

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

like image 65
Onik Avatar answered Sep 27 '22 15:09

Onik