Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app OOM (Out Of Memory) adjustment priorities for processes

I am developing an Android Launcher (Home screen replacement) application and running into the launcher getting killed in low-memory situations. This is obviously not great when the user returns home and has to wait.

In my research, I've found that Android classifies processes into several priority groups, from highest to lowest:

System

Persistent

Foreground

Visible

Perceptible

A Services

Home

Previous

B Services

Background

You can examine what processes fall under which by executing: adb shell dumpsys meminfo

The most comprehensive documentation I could find on this topic was: http://developer.android.com/guide/components/processes-and-threads.html#Lifecycle

However, it does not give a clear picture of all the groups mentioned above. Specifically,

  1. How/when is a process considered "Perceptible"? Some apps (such as the Go Launcher EX), seem to have figured out how to stay in this category when not in foreground. This way, it does not get killed as often. How are they doing it?

    I find from adb shell dumpsys activity that Go Launcher Ex is considered a foreground service. The only documentation I can find on this subject says that you need to put a persistent notification in the status bar. However, Go Launcher Ex somehow got around this requirement. I'm lost as to how:- (

  2. What's the difference between "A Services", "Home", and "B Services"?

  3. Any other general advice for a launcher application on how it can gain higher priority than a regular app? I think this is a completely legitimate request given that a launcher should be considered higher priority than most things (except current foreground activity) for users.

like image 349
dubchoi Avatar asked Dec 04 '12 22:12

dubchoi


1 Answers

to answer question 1) and 3)
if you logcat -b events you can see those applications with priority perceptible indeed create a notification. But all properties (even contentView) set to null.
So on my research for same problem I just tried to create an empty Notification and start my Service with it:

startForeground(42, new Notification())

and voilà: logcat says:

I/notification_enqueue( 1607): [my.testapp.TestApp,42,NULL,Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 kind=[null])]

and dumpsys meminfo:

...
17539 kB: Perceptible  
     ...  
     6164 kB: my.testapp.TestApp (pid 25573)  
...

I don't think this is intended, and it should be understood that this should only be used if really really required. I don't want to imagine every lousy service using this.

like image 51
Jantlem Avatar answered Sep 22 '22 17:09

Jantlem