0

I am using MediaBrowserServiceCompat in my app to play music. I am also starting service with startService method within the service and also using startForeground with notification as well as using wakelock require. But still my service is being destroyed after lock.

startService(new Intent(getApplicationContext(),
                            PlaybackService.class));

mService.startForeground(NOTIFICATION_ID, notification);

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mWakeLock.acquire();
Andronicus
  • 25,419
  • 17
  • 47
  • 88
  • Look here, you might find something: https://stackoverflow.com/questions/36399123/is-it-possible-to-run-service-in-android-platform-continuously-even-after-lockin – Anuraag Baishya Mar 08 '18 at 11:23

1 Answers1

0

Calling Context.startForeground() instead of Context.startForegroundService() on Oreo+ devices can cause trouble. Try to check Build version and call the appropriate method:

For Oreo+: startForegrountService()

For lower than Oreo: startForeground()

Andronicus
  • 25,419
  • 17
  • 47
  • 88