如何重现:
绑定服务并致电startForeground(true)
Intent intent = new Intent(this, MediaPlayerService.class);
bindService(intent, connection, Context.BIND_AUTO_CREATE);
从最近的应用中删除我的应用
startForeground(false)
会保留通知,但可以通知。适用于Android 6.0,但在4.1.1上它会重启我的服务:
D/MediaPlayerService: freeNotification...
I/ActivityManager: Killing 5163:org.test.app.debug/u0a50: remove task
W/AudioService: AudioFocus audio focus client died
I/AudioService: AudioFocus abandonAudioFocus(): removing entry for android.media.AudioManager@5367ef4ccom.kometared.audiomaterialapp.audioservice.MediaPlayerService$2@536c2c24
W/AudioService: RemoteControlClient died
W/ActivityManager: Scheduling restart of crashed service org.test.app.debug/com.kometared.audiomaterialapp.audioservice.MediaPlayerService in 5000ms
在Android 5.0 / 5.1上,它遵循类似的结果,但服务甚至没有重新启动:
D/MediaPlayerService: freeNotification...
I/ActivityManager: Killing 2181:org.test.app.debug/u0a61 (adj 9): remove task
W/MediaFocusControl: AudioFocus audio focus client died
I/MediaFocusControl: AudioFocus removeFocusStackEntry(): removing entry for android.os.BinderProxy@1c6e92f6
W/libprocessgroup: failed to open /acct/uid_10061/pid_2181/cgroup.procs: No such file or directory
W/ActivityManager: Scheduling restart of crashed service org.test.app.debug/com.kometared.audiomaterialapp.audioservice.MediaPlayerService in 1000ms
W/MediaSessionRecord: Removing dead callback in pushEvent.
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:496)
at android.media.session.ISessionControllerCallback$Stub$Proxy.onSessionDestroyed(ISessionControllerCallback.java:189)
at com.android.server.media.MediaSessionRecord.pushSessionDestroyed(MediaSessionRecord.java:613)
at com.android.server.media.MediaSessionRecord.access$3800(MediaSessionRecord.java:66)
at com.android.server.media.MediaSessionRecord$MessageHandler.handleMessage(MediaSessionRecord.java:1232)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at com.android.server.SystemServer.run(SystemServer.java:271)
at com.android.server.SystemServer.main(SystemServer.java:172)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
这是一个错误吗?或者我做错了什么?