Search code examples
androidandroid-serviceandroid-service-binding

Service being stopped


I am trying to show notification for an RSS feed in my android application. the background service works fine in some mobile. but the problem is Huawei phone always kills the background service. I have tried many solutions in the last 5 days, none of them is working. When the app is closed, service is killed immediately.

I have tried,

  1. making the service sticky.
  2. using internet service which runs after regular interval.
  3. use the foreground server.
  4. restart service onDestroy event.
  5. using alarm manage to restart the service and many more.

Solution

  • Foreground A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track. Foreground services must display a Notification. Foreground services continue running even when the user isn't interacting with the app.

    Background A background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service.

    Note: If your app targets API level 26 or higher, the system imposes restrictions on running background services when the app itself isn't in the foreground. In most cases like this, your app should use a scheduled job instead.

    you should use Foreground service.

    please check this link. https://developer.android.com/guide/components/services