2

When I clear my app from recent apps list, my app background service killed. I tried with android nougat and oreo. But it's working in Android 6.0. After searched about the issue. Lot of people navigated the answer to Background Execution Limits.

Any one have solution for this issue?

Saravanan S
  • 123
  • 1
  • 13

3 Answers3

1

Android Nougat should not have those issues ideally. I've spend weeks on NotificationListenerService which runs perfectly fine in background in Nougat. It also works great in Samsung S9 (Android Oreo) but I have some issues in Google devices and emulators. I've raised a similar issue few weeks back.

Just to make sure, enable background services for your app through console. Also, specify which service you are using?

Sushant Somani
  • 1,450
  • 3
  • 13
  • 31
1

try this

@TargetApi(Build.VERSION_CODES.O)
    private void moveToStartedState() {
        Intent intent = new MyIntentBuilder(this)
            .setCommand(Command.START).build();
        if (isPreAndroidO()) {
            Log.d(TAG, "Running on Android N or lower");
            startService(intent);
        } else {
            Log.d(TAG, "Running on Android O");
            startForegroundService(intent);
        }
    }

Example

https://proandroiddev.com/deep-dive-into-android-services-4830b8c9a09

Gautam Surani
  • 1,136
  • 10
  • 21
1

Simple answer:

Use foreground services instead of background services.

Why?

Because of changes in how latest Android SDKs treat background services and Doze mode.


Good luck :)

Tomas Jablonskis
  • 4,246
  • 4
  • 22
  • 40
  • Thanks for your quick reply. I have android nougat 7.1.2, mobile RedMi5A. At beginning my background service worked very well. But yesterday to that background service functions are killed and the services are not restarted when I clear my app from recent apps. I checked 1.Autostart, 2.Battery Consumptions, 3. Background service all are enabled. Now the problem is that background service is not restarting when i swiped app from recent app list. – Saravanan S Aug 08 '18 at 06:12
  • Maybe you changed something in the code? Tried reinstalling your app? – Tomas Jablonskis Aug 08 '18 at 06:20
  • I didn't changed, Because of that app in play store. That's what I totally confused. It's too strange. But it's perfectly working in Android 6.0. – Saravanan S Aug 08 '18 at 06:36
  • Using foreground service is relevant only for specific scenarios, so I think it might not be the right solution for this problem (see here https://stackoverflow.com/a/9323576/997940) – Yoav Feuerstein Feb 11 '19 at 14:02