Skip to content

Pass the context to shouldStartForegroundService #1887

Closed

Description

@johngray1965

[REQUIRED] Use case description

In order to implement androidx.media3.session.MediaButtonReceiver.shouldStartForegroundService, I need to inject something. I can either use @androidentrypoint or use @entrypoint. The former doesn't work because the dagger generated code overrides onReceive and androidx.media3.session.MediaButtonReceiver implementation of onReceive is final. The latter doesn't because I don't have context needed to use the @entrypoint.

Proposed solution

Where the androidx.media3.session.MediaButtonReceiver calls shouldStartForegroundService, it has a context. In fact it uses when it calls ContextCompat.startForegroundService, in order to correctly implement shouldStartForegroundService I need same information.

Alternatives considered

Copying the code from androidx.media3.session.MediaButtonReceiver to implement my own (not a great option).

Note, this is with 1.5.0-rc01

Activity

  1. marcbaechinger commented on Nov 14, 2024

    @marcbaechinger
    Contributor

    Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

  2. johngray1965 commented on Nov 14, 2024

    @johngray1965
    ContributorAuthor

    Yup, that is a valid request. Thanks for the suggestion. We will pass the context, we get in onReceive to shouldStartForegroundService. We will update this issue when this lands in the main branch.

    Thank you. That'll be very helpful.

  3. marcbaechinger commented on Nov 18, 2024

    @marcbaechinger
    Contributor

    The change is available in main and will be included in the next release. Thanks for the suggestion!

  4. locked and limited conversation to collaborators on Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions