I have an android remote service which is accessed and use its functionalities by client apps through AIDL. I have some doubts regarding that about the low memory case.While the remote service is used by multiple clients/apps, probably had a chance for getting killed by OS on situations like low memory.I am looking for a solution to that.
1 Answers
While the remote service is used by multiple clients/apps, probably had a chance for getting killed by OS on situations like low memory.
The effective importance of a process exposing an AIDL interface is the higher of:
- the intrinsic importance of that process, and
- the highest importance of any clients of that process
Higher-importance processes are more likely to be left alone by the "out-of-memory killer", the part of the OS that terminates Android SDK apps' processes to free up system RAM for use by other apps' processes.
Hence, so long as you have active clients, and those clients are important, your app will be important. Conversely, if you have no active clients, or those clients are not important, your process will not be important.
How can we prevent Android-Remote-Service from getting killed by OS ,because of low memory?
Build your own firmware, where you implement this service as a native Linux daemon instead of it being an Android SDK app.
Otherwise, your process can be terminated at any point, for low memory, by user action (e.g., "Force Stop" in Settings), or possibly for other reasons (e.g., unhandled exception).
You can make your service a foreground service, to ensure that it has high importance and is unlikely to have its process be terminated. This has costs, in the form of a Notification
that the user will see.
Instead, ideally, you design your app such that process termination is not an issue.

- 986,068
- 189
- 2,389
- 2,491
-
So, Are you saying that adding this remote service to AOSP as a system service will help or anything else need to be done? – SachinS Aug 22 '17 at 19:16
-
@SachinS: "Are you saying that adding this remote service to AOSP as a system service will help" -- I am saying that the out-of-memory killer only kills Android SDK processes, those forked from the zygote. Ordinary Linux daemons are immune to the out-of-memory killer and cannot be stopped by the user through Settings. – CommonsWare Aug 22 '17 at 19:20
-
"Implement this service as a native Linux daemon instead of it being an Android SDK app" .Where can I get help/steps regarding this? – SachinS Aug 22 '17 at 19:30
-
@SachinS: I cannot point you to specific instructions. https://source.android.com/ has details of working with the AOSP to build firmware. Karim Yaghmour's book and course on Android internals should go into this process in greater detail, and most likely there are other resources beyond those. – CommonsWare Aug 22 '17 at 19:32