Monday, August 2, 2010

Re: [android-developers] Re: Froyo -- How to detect that my application has been killed?

Correct, onDestroy() is not called when it is killed.  This is the same as activity -- the kernel kills processes when needed, not waiting for the app.

The status bar is correctly keeping the icon.  The service will later be restarted; it has not been stopped.

It is normal for background services to be killed regularly.  This is intentional, because generally background services are not something the user is directly aware of, and restarting their processes every now and then avoids issues with such services consuming increasing amounts of RAM.

If your service is something the user is actually aware of (such as music playback), consider Service.startForeground().

On Sat, Jul 31, 2010 at 2:08 AM, Happy C. <taiwanhappiness@gmail.com> wrote:
Hi Dianne,
I have the same issue with the froyo.

I use the start service UI as the following code.

//CurrentActivity.java (extend from ListActivity)
Intent intent_start_service=new
Intent(CurrentActivity.this,MyRunningService.class);
intent_start_service.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startService(intent_start_service);

I always get the following log message after starting the service
around 30 mins~2hours, and the service is not working anymore.

07-31 15:03:00.001: INFO/ActivityManager(85): No longer want
com.Myapplication (pid 4726): hidden #16
07-31 15:03:00.091: WARN/ActivityManager(85): Scheduling restart of
crashed service com.Myapplication/.MyRunningService in 5000ms
07-31 15:03:05.131: INFO/ActivityManager(85): Start proc
com.Myapplication for service com.Myapplication/.MyRunningService:
pid=5045 uid=10077 gids={}

The MyRunningService seems to be killed by the OOM, and the
notification icon on the status bar with "Ongoing" is also shown to
the user. Besides, I don't see any message from my customized log
message in the onDestroy() of this service.

//MyRunningService.java

       public void onDestroy()
       {
         Log.e(TAG,"Oh!!MyRunningService was killed ");
        }
//

The issues:
1. Why MyRunningService is always killed by the OOM? Can I prevent it
or can I detect the killing behavior by the service itself and restart
the service automatically with some good solution?
2. Is there any way to clean the notification icon as the service is
been killing ?

Thank you very much!


On 7月31日, 上午3時38分, Dianne Hackborn <hack...@android.com> wrote:

> For the behavior you are seeing, are you using the bind server instead of
> the start service UI?  If you do that then yes your service will not be
> restarted -- because the process that is bound to it is in the background,
> so free to be killed, and once it gets killed the binding goes away and the
> service does not need to run any more.
>
> But this exact behavior is expected to happen when the device is low on
> memory, so it is something apps need to deal with correctly anyway.

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hackbod@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment