START_STICKY, foreground Android service goes away without notice

前端 未结 2 1543
南旧
南旧 2020-12-10 06:54

I have started a service in my new application. The service is foregrounded, with a Notification. When this is run in the AVD 2.1 API Level 7, all works fine. But when it

2条回答
  •  萌比男神i
    2020-12-10 07:34

    A few things:

    1. Get rid of the mNotificationManager.notify(NOTIFICATION_ID, notification);. startForeground() displays the notification icon for you.

    2. Foreground Services can still be killed, they're just less likely to be.

    3. There's a bug in 2.3 (not sure if it was fixed yet) where when a Service is killed and restarted, its onStartCommand() will NOT be called again. Instead you're going to have to do any setting up in onCreate().

提交回复
热议问题