sockeqwe sockeqwe - 1 year ago 77
Android Question

Can I put an Intent Service into a library project and use it in different apps?

Im working on a library with an Intent Service. I want to use this IntentService in different apps, that probably are installed in parallel on the users device.

Let's assume I have two android applications. Both use my library and want to use my IntentService (part of the library). I dont want to make something like a "shared service", both apps are independed, both service should run independent from each other.

In the first apps Android Manifest I specify the service as follows:

<service android:name="com.mylibrary.service.SuperService" android:enabled="true"/>

In the second app I will do the same:

<service android:name="com.mylibrary.service.SuperService" android:enabled="true"/>

Does it make conflicts, because both apps have the same package and name? Does Android know which SuperService instance belongs to which app?

Answer Source

there will not be any conflict with that scenes each process running independently it own instances, and the fact that both of them running same service name (and package name) don't cause any problem.

I know that for sure, simply because I'm doing the same thing myself for a long time - using same library Service in two different apps that runs simultaneity on same device

under the hood, Service is simply implemented as kind of singltone that the OS manage it lifecyle in special way then other Java classes, but eventually it's still an instance running inside your own process memory sandbox.

Same with IntentService, that extends Service

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download