On Tue, Dec 15, 2009 at 12:05 PM, Don Park <don.p...@gmail.com> wrote:

> I understand that a service can be bumped out of ram, though I
> expected this to happen infrequently enough, with a quick enough
> restart time, that the service was effectively running 24 hours a day.
> a 10 minute gap for instance would be fine.
>

If you are running on a G1, as you state, the system is very tight on memory
and you can assume that just it doing things in the background at some point
will cause it to get killed.  Also, as a protective measure, for
long-running services we eventually move them out of the "service" class
into the "background" memory class, giving them a greater chance to get
killed.  Otherwise, any such service with a memory leak can easily cause
stress on the system.

When a service is deemed unnecessary, its killed outright (meaning
> killed at the unix process level)? with no callback or chance to
> cleanly shutdown?


It is never deemed "unnecessary."  A service, by definition, is something
that is wanting to run.  Unfortunately there is very often not enough RAM
available at certain points to keep all such services running as well as
other things that are needed, so something needs to give, and the next thing
after truly background processes are service processes.

An overview of this mechanism can be found here:

http://developer.android.com/guide/topics/fundamentals.html#proclife


> I'm surprised by that. When *does* onDestroy get
> called?


Because the kernel is killing the process to meet its memory demands.
 Giving the process a chance to stop this would prevent the system from
being able to avoid bad paging states.


> I use a notification icon to alert the user that the service
> is indeed running. With the service killed, it appears to the user
> that the service is not killed as the notification is not removed.
>

If this is something the user should actually be this aware of, you should
consider this API:

http://developer.android.com/reference/android/app/Service.html#startForeground(int,
android.app.Notification)


> I cannot say why the service is not being restarted. I just started
> the app in the emulator but a kill nor a kill -9 make the app do
> anything in the emulator - it continues to run.


Then you didn't kill it. :)


> I do not see a process
> listing for the service, just the package name for the whole app.
> Should I be seeing a seperate process for a service?
>
> # ps
> ...
> app_24   217   29    115908 24880 ffffffff afe0d4a4 S
> com.icecondor.nest
>
> # kill app_24
> # kill -9 app_24
> (no change in the emulator, the app is still responsive in the
> emulator)
>

This is not right.  "app_24" is the uid of the process.  You should use the
pid as the argument to kill.  You don't need -9; just "kill 217" will do it.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

Reply via email to