question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ForegroundServiceStartNotAllowedException stopping playback

See original GitHub issue

We have many reports from Android 12 users claiming that the app crashes or the audio quality deteriorates with playback while the screen is off.

Here are the logs from 1 customer:

E 17/3 22:25:04 Playback service error
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service au.com.shiftyjelly.pocketcasts/.core.player.PlaybackService
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
	at android.os.Parcel.readParcelable(Parcel.java:3333)
	at android.os.Parcel.createExceptionOrNull(Parcel.java:2420)
	at android.os.Parcel.createException(Parcel.java:2409)
	at android.os.Parcel.readException(Parcel.java:2392)
	at android.os.Parcel.readException(Parcel.java:2334)
	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7096)
	at android.app.Service.startForeground(Service.java:733)
	at au.com.shiftyjelly.pocketcasts.core.player.PlaybackService$MediaControllerCallback.onPlaybackStateChangedWithNotification(PlaybackService.kt:10)
	at au.com.shiftyjelly.pocketcasts.core.player.PlaybackService$MediaControllerCallback.access$onPlaybackStateChangedWithNotification(PlaybackService.kt:1)
	at au.com.shiftyjelly.pocketcasts.core.player.PlaybackService$MediaControllerCallback$4.invoke(PlaybackService.kt:3)
	at au.com.shiftyjelly.pocketcasts.core.player.PlaybackService$MediaControllerCallback$4.invoke(PlaybackService.kt:1)
	at ek.l.b(Unknown Source:2)
	at pj.r.onNext(LambdaObserver.java:2)
	at uj.c2$a.d(ObservableObserveOn.java:8)
	at uj.c2$a.run(ObservableObserveOn.java:3)
	at ij.b$b.run(HandlerScheduler.java:1)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7839)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.os.RemoteException: Remote stack trace:
	at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1837)
	at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1350)
	at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:11903)
	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3205)
	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2498)

ApplicationExitInfo(timestamp=18/03/22, 9:35 pm pid=19707 realUid=10237 packageUid=10237 definingUid=10237 user=0 process=au.com.shiftyjelly.pocketcasts reason=9 (EXCESSIVE RESOURCE USAGE) subreason=7 (EXCESSIVE CPU USAGE) status=0 importance=400 pss=158MB rss=175MB description=excessive cpu 22790 during 300121 dur=1781131 limit=2 state=empty trace=null

Device info:

App version : 7.19.2 (7566)
Sync account: rorypnd@gmail.com
Last Sync: 2022-03-18T10:34:59.987Z
Time: 2022-03-18 23:35:09 Local
      2022-03-18 10:35:09 Utc
Background refresh: true

Phone: Google - oriole - Pixel 6 - oriole
Kernel: 5.10.43-android12-9-00007-g9771767708df-ab8009062 - abfarm-release-rbe-64-00086
Android version: 12 SDK 31
Phone ID: 929e6fab-74fe-4a75-8b4d-2fa40c562bf9

#4871871-zen #4885182-zen

Both reported that setting the battery optimization to unrestricted for Pocket Casts resolved it. There have been users, however, who have reported that updating the battery optimization setting has not fixed the issue.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ashiagrcommented, Dec 7, 2022

FYI

Latest Cast SDK (21.2.0) includes this release note:

Fixed ForegroundServiceStartNotAllowedException with the MediaNotificationService.

The SDK version is updated in v7.28 in this PR. Hopefully, we’ll stop seeing this issue while casting. 🤞

0reactions
mchowningcommented, Dec 7, 2022

🤦 I looked at the wrong PR! Sorry about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting ForegroundServiceStartNotAllowedException #111
We want to stop the playback when the app is removed from the recent activities, so that's why we call stopSelf() there, does...
Read more >
Android 12 ForegroundServiceStartNotAllowedException ...
I believe this is a bug in Android 12, it is preventing foreground services even in situations which are supposed to be allowed....
Read more >
ForegroundServiceStartNotAllow...
ForegroundServiceStartNotAllowedException when targeting 31+ and controlling playback via Google Assistant ; Comments (15) ; Duplicates (0) ; Blocking (0) ...
Read more >
Foreground services - Android Developers
Build TV playback apps. Overview. UI guidance & Leanback API. Create a catalog browser · Provide a card view · Build a details...
Read more >
Foreground service launch restrictions-Android12
If an application attempts to start a foreground service while running in the background, the ForegroundServiceStartNotAllowedException exception ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found