Hi,

please, read my question carefully. I'm asking about a specific case, when 
Android OS "kills" a SERVICE (an application component) separately, without 
killing entire PROCESS. You are talking about the case, when Android OS 
kills entire background PROCESS, because it has low priority compared to 
other running PROCESSES.

Thank you,
Alex


On Tuesday, December 9, 2014 7:57:36 AM UTC+1, gjs wrote:
>
> Hi,
>
> You can prove this yourself by creating a test app with a service & 
> running a few tests.
>
> Run the test app & start the service on a recent device with Android V4+ 
> then leave the service running & go & do other stuff for a while.
>
> Sometime during the next few hours you probably find that your service has 
> been killed by the OS regardless of whether the service was busy or not (& 
> regardless of OOM pressure).
>
> If you want the service to remain running longer than a few hours you will 
> need to use 'startForeground' 
> http://developer.android.com/reference/android/app/Service.html#startForeground(int,
>  
> android.app.Notification) but even that will not prevent the OS from 
> killing your service when it thinks it really needs to due to memory 
> pressure.
>
> Once upon a time before approximately Android V2.2 services were left 
> running indefinitely & weren't eagerly killed by the OS ( even without 
> having to specify 'startForeground' or 'setForeground' ) provided there was 
> no memory pressure, but that's no longer the case.
>
> What's officially documented & what actually happens on real devices will 
> vary, so prove to your own satisfaction by testing...
>
> Regards
>
> On Tuesday, December 9, 2014 12:01:12 PM UTC+11, Peter Teoh wrote:
>>
>> *The Service can still be killed by Android.*
>>
>>
>> Any proofs?
>>
>> not any proofs, but just some discussion is possible:
>>
>> Read this:
>>
>>
>> http://developer.android.com/reference/android/content/Context.html#startService%28android.content.Intent%29
>>
>> From above, there is a line:   
>>
>> The only time they should be stopped is if the current foreground 
>> application is using so many resources that the service needs to be killed.
>>
>> This is talking about the OOM killer.
>>
>> In traditional Linux OOM is initiated from the kernel.   But here in 
>> Android there is a special lowmemorykiller daemon:
>>
>> https://source.android.com/devices/tech/low-ram.html   (looked out for 
>> lowmemorykiller, the name as it is)
>>
>> Under Android source code:
>>
>>
>> frameworks/base/services/core/java/com/android/server/am/ActiveServices.java:
>>     final void killServicesLocked(ProcessRecord app, boolean 
>> allowRestart) {
>>
>>
>> frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java:
>>         mServices.killServicesLocked(app, allowRestart);
>>
>> You can see the caller and the implementer of the function above.   It is 
>> where BIND_ALLOW_OOM_MANAGEMENT parameter are checked, and thus killing the 
>> services is done if necessary.
>>
>> More info:
>>
>>
>> http://stackoverflow.com/questions/18972590/the-timing-to-start-android-low-memory-killer
>>
>> http://forum.xda-developers.com/showthread.php?t=904023
>>
>> And this is from Linux kernel source code (under drivers/staging/android 
>> means it is still yet to be approved by linux kernel - at that time):
>>
>>
>> http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/drivers/staging/android/lowmemorykiller.txt
>>
>> http://www.programering.com/a/MjNzADMwATE.html
>>
>> http://lwn.net/Articles/511731/
>>
>> http://varun-anand.com/mem_mgmt.html
>>
>> Regards, 
>> Peter Teoh
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to