foregroundappchecker icon indicating copy to clipboard operation
foregroundappchecker copied to clipboard

[BUG] Android 8+ service stops

Open Duna opened this issue 5 years ago • 0 comments

The way you start service is killed by OS after 20 seconds Please have a lecture: https://developer.android.com/about/versions/oreo/background Use startForegroundService() method instead of startService().

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            ctx.startForeground(NOTIFICATION_ID, mBuilder.build());
        } else {
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx);
            notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }

...

Duna avatar Oct 22 '19 19:10 Duna