androidintentservice

Rename exported Intent Service


I have multiple apps on the same device, one of them has an IntentService which gets called from the other apps via:

 val intent = Intent()
 intent.component = ComponentName(APP_PACKAGE, INTENT_APP_SERVICE)
 intent.putExtras(key, value)
 context.startService(intent)

Everything works as expected.

My question is, what happens when i change the name of the service in the app which exports it? Do i have to change the INTENT_APP_SERVICE to match the new name as well? Or is there another way to be backwards compatible?


Solution

  • what happens when i change the name of the service in the app which exports it?

    You are screwed, unless you can somehow force every user to update every one of your apps.

    Do i have to change the INTENT_APP_SERVICE to match the new name as well?

    Yes, given the setup that you have.

    Or is there another way to be backwards compatibility?

    Step #1: Add an <intent-filter> to the <service> with a custom action

    Step #2: Set up your startService() Intent to use that action, plus setPackage(), instead of a ComponentName

    Now, your service's clients are independent of the name of the service itself, so you can refactor or otherwise rename that service without issue.