当我在 api 级别 19 中调用 stopForeground 时,服务将被破坏

When i call stopForeground in api level 19 then service will destroy

当我在 api 级别 19 中调用 stopForeground 时,服务将被破坏,但是当我在 api 级别 24 中调用 stopForeground 时,服务将不会被破坏 谁能帮我找出 api 级别 20、21、22 和 23 中的这种情况?

你提供什么标志 stopForground(int) 文档声明使用 STOP_FOREGROUND_REMOVE 尽管不清楚提及它可能会破坏服务。

您可以尝试使用标志 STOP_FOREGROUND_DETACH 并在不再需要时通过 NotificationManager 手动删除通知。

参考文档:stopForground(int) flags