As this issue is still present, I've tracked it down further into the broadcast receiver code. When the broadcast is being delivered it removes the service from foreground state and then kills it.
Info added here, since the workaround is not good. https://code.google.com/p/android/issues/detail?id=53313#c3 On Thursday, July 19, 2012 5:19:22 PM UTC-4, Andy dev wrote: > > I've got a service running (an accessibility service called > MainRunningService) and also use an alarmmanager within my app. > > On ICS when a user pulled up the task list and swiped the app away the > service kept running, but the user interface was cleared from the stack. > > On jelly bean I'm finding this to be a little different. It seems like it > kills off the service and then restarts it even if I've got an icon in the > notification bar and I've got the app set to run in the foreground. This is > killing off all my current app state and causing it to stop working. > > I'm seeing this in the logs > > 07-19 21:47:42.213: I/ActivityManager(307): Killing > 834:com.example.android.appname/u0a72: remove task > 07-19 21:47:42.236: W/AudioService(307): AudioFocus audio focus client > died > 07-19 21:47:42.236: I/AudioService(307): AudioFocus abandonAudioFocus(): > removing entry for > android.media.AudioManager@41a42020com.example.android.appname.service.MainRunningService$1@41963ec0<javascript:> > 07-19 21:47:42.244: W/ActivityManager(307): Scheduling restart of crashed > service com.rageconsulting.android.appname/.service.MainRunningService in > 5000ms > > For the persistent Icon I'm doing the following: > Notification foregroundNotification; > foregroundNotification = new Notification(R.drawable.iconx,"Example > starting notification",System.currentTimeMillis()); > Intent i=new Intent(this, MainUIActivity.class); > i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); > foregroundNotification.flags|=Notification.FLAG_NO_CLEAR; > startForeground(9642, foregroundNotification); > > > > Is there something I'm doing wrong? I've never had a problem in the past > with this code, but it's not very good on jelly bean. > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

