I've pinpointed the logic error in PlayerNotificationListener.kt. The isForegroundService flag was being set to false even when the notification was just being updated, not dismissed by the user. This made the service vulnerable to being killed by the system. Moved the isForegroundService = false line to be within the if (dismissedByUser) block. This change ensures that the service remains in a foreground state when paused, which is the correct behavior. This should resolve the issue where Android Auto fails to resume playback.
The current onTaskRemoved implementation is too aggressive and stops the service even when paused. The correct approach is to let the service continue running when the app is swiped from the recents list. The service's lifecycle is already correctly managed by the PlayerNotificationManager, which will stop the service when the user dismisses the notification (which is only possible when playback is paused).
How have you tested this?
Still testing since it is intermittent. Also want to see the affects on battery life if any.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/advplyr/audiobookshelf-app/pull/1640
**Author:** [@AwsomeFox](https://github.com/AwsomeFox)
**Created:** 7/23/2025
**Status:** 🔄 Open
**Base:** `master` ← **Head:** `fix-session-resume`
---
### 📝 Commits (1)
- [`a735336`](https://github.com/advplyr/audiobookshelf-app/commit/a735336d69e0f431c6e45cd30121b57b46ac97fd) fix: session resumption issues
### 📊 Changes
**2 files changed** (+1 additions, -3 deletions)
<details>
<summary>View changed files</summary>
📝 `android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt` (+1 -1)
📝 `android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt` (+0 -2)
</details>
### 📄 Description
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.
If you do not follow this template, the PR may be closed without review.
Please ensure all checks pass.
If you are a new contributor, the workflows will need to be manually approved before they run.
-->
## Brief summary
Fixes session resumption problems by altering logic when updating notification and when user swipes away application.
<!-- Please provide a brief summary of what your PR attempts to achieve. -->
## Which issue is fixed?
Should fix
https://github.com/advplyr/audiobookshelf-app/issues/1309
<!-- Which issue number does this PR fix? Ex: "Fixes #1234" -->
## Pull Request Type
Only android
<!--
Does this affect only Android, only iOS, or both?
Does this change the frontend or the backend of the apps?
-->
## In-depth Description
I've pinpointed the logic error in PlayerNotificationListener.kt. The isForegroundService flag was being set to false even when the notification was just being updated, not dismissed by the user. This made the service vulnerable to being killed by the system. Moved the isForegroundService = false line to be within the if (dismissedByUser) block. This change ensures that the service remains in a foreground state when paused, which is the correct behavior. This should resolve the issue where Android Auto fails to resume playback.
The current onTaskRemoved implementation is too aggressive and stops the service even when paused. The correct approach is to let the service continue running when the app is swiped from the recents list. The service's lifecycle is already correctly managed by the PlayerNotificationManager, which will stop the service when the user dismisses the notification (which is only possible when playback is paused).
<!--
Describe your solution in more depth.
How does it work? Why is this the best solution?
Does it solve a problem that affects multiple users or is this an edge case for your setup?
-->
## How have you tested this?
<!-- Please describe in detail with reproducible steps how you tested your changes. -->
Still testing since it is intermittent. Also want to see the affects on battery life if any.
Update: tested after overnight and killing the app. The book resumes in android auto just fine now. I did test with https://github.com/advplyr/audiobookshelf-app/pull/1641 at the same time.
## Screenshots
<!-- If your PR includes any changes to the front-end, please include screenshots or a
short video from before and after your changes. -->
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/advplyr/audiobookshelf-app/pull/1640
Author: @AwsomeFox
Created: 7/23/2025
Status: 🔄 Open
Base:
master← Head:fix-session-resume📝 Commits (1)
a735336fix: session resumption issues📊 Changes
2 files changed (+1 additions, -3 deletions)
View changed files
📝
android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationListener.kt(+1 -1)📝
android/app/src/main/java/com/audiobookshelf/app/player/PlayerNotificationService.kt(+0 -2)📄 Description
Brief summary
Fixes session resumption problems by altering logic when updating notification and when user swipes away application.
Which issue is fixed?
Should fix
https://github.com/advplyr/audiobookshelf-app/issues/1309
Pull Request Type
Only android
In-depth Description
I've pinpointed the logic error in PlayerNotificationListener.kt. The isForegroundService flag was being set to false even when the notification was just being updated, not dismissed by the user. This made the service vulnerable to being killed by the system. Moved the isForegroundService = false line to be within the if (dismissedByUser) block. This change ensures that the service remains in a foreground state when paused, which is the correct behavior. This should resolve the issue where Android Auto fails to resume playback.
The current onTaskRemoved implementation is too aggressive and stops the service even when paused. The correct approach is to let the service continue running when the app is swiped from the recents list. The service's lifecycle is already correctly managed by the PlayerNotificationManager, which will stop the service when the user dismisses the notification (which is only possible when playback is paused).
How have you tested this?
Still testing since it is intermittent. Also want to see the affects on battery life if any.
Update: tested after overnight and killing the app. The book resumes in android auto just fine now. I did test with https://github.com/advplyr/audiobookshelf-app/pull/1641 at the same time.
Screenshots
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.