Search code examples
androidandroid-serviceforeground-serviceapi-versioning

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


When i call stopForeground in api level 19 then service will destroy but when i call stopForeground in api level 24 then service will not destroy can anyone help me to find out this scenario in api level 20 ,21 , 22 and 23?


Solution

  • What flag are you providing stopForground(int) docs state that using STOP_FOREGROUND_REMOVE although unclear mention it could destroy the service.

    You could try using the flag STOP_FOREGROUND_DETACH and manually delete the notification if no longer required through the NotificationManager.

    Docs for reference : stopForground(int) flags