我有一个intentService,在onHandleIntent()中,我在开始时调用了startForeground()并在stopForeground在方法的末尾。当我调用stopForeground(false)时,即使我指定保留它,通知也会被删除。文档说:“如果您在服务仍在前台运行时停止该服务,则通知也会被删除。”因此,当intentService出于某种原因调用stopSelf()时,服务似乎再次处于前台状态。正确行为的唯一方法是在stopForeground(true)之后创建一个新通知。我错过了什么吗? 最佳答案 当
我想在我的前台服务被销毁后删除一个通知。我尝试从onDestroy()和unbind()调用stopForeground(true)。尽管调用了onUnbind()和onDestroy()(我可以从日志中看到)通知仍然存在。我通过从我的Activity中调用unbindService(playerConnection)和stopService(this)来停止服务。为什么这样不行?关于如何在服务被破坏时删除通知有什么想法吗?更新:我在玩弄通知时注意到一件有趣的事。我在服务中做了一个特殊的方法:funhideNotification(){stopForeground(true)Log.d
我有一个媒体服务,它使用startForeground()在播放开始时显示通知。播放时有暂停/停止按钮,暂停时有播放/停止按钮。NotificationCompat.BuildermBuilder=newNotificationCompat.Builder(this);//setup...Notificationn=mBuilder.build();if(state==State.Playing){startForeground(mId,n);}else{stopForeground(false);mNotificationManager.notify(mId,n);}这里的问题是当我