androidx / androidx/media

How to stop the service when the app is dismissed from recent tasks

Open
#482 1 comment 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Jun 27, 2023.

documentation candidate question
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Media3 Version

Media3 1.1.0-alpha01

Devices that reproduce the issue

Pixel 4 API 33 or any device

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

Launch the demo-session app. Play any song.

We have this code here

override fun onTaskRemoved(rootIntent: Intent?) {
    If (!player.playWhenReady) {
      stopSelf()
    }
  }

The question is how to close the app when I swipe the app from recents?
If I remove this check if (!player.playWhenReady) and call stopSelf() app is leaking. App is not visible in recents but android studio profiler shows that it is running and the service still takes memory.

Adding player.stop() before stopSelf() in onTaskRemoved(rootIntent: Intent?) also not helping.
So I'm looking for a solution to close the app and free all resources when swiping from recents or clicking on custom button in notification.

One more question. When killing the app by

val id = Process.myPid()
Process.killProcess(id)

sometimes the service restarts itself. Why does it happen?

Expected result

I need a way to close the app and free memory in both cases when Exoplayer is playing/paused.

Actual result

Demo app release resources only when exoplayer is paused. !player.playWhenReady

Media
Screenshot 2023-06-27 at 13 15 57
Bug Report
  • You will email the zip file produced by adb bugreport to dev.exoplayer@gmail.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.