Skip to content

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

Open
@picklepickle1

Description

@picklepickle1

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 [email protected] after filing this issue.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions