Reputation: 4274
I have a library that contains a subclass of the Android Application class. The sub-class contains a method that launches a service (also contained in the library project).
When I include the library in my host application, the activity manager complains that it is unable to start the service intent (not found).
The code structure is:
<service name="com.my.project.MyService" />
Intent intent = new Intent(this, MyService.class);
startService(intent);
I can resolve the issue by defining the service again in the host applications manifest; However, I would prefer not to impose this requirement on developers using the library.
My question is, can I avoid the requirement for referencing the libraries service in the hosts manifest?
Upvotes: 2
Views: 448
Reputation: 10485
Worth mentioning, though it won't affect you as of your current implementation (if I read it correctly), is that one should pay attention to which Context
one passes on to the Intent
constructor.
If you for example decide to move your Service
to a separate APK, that service won't be found in the client applications Context
.
You could then instead use an alternative Intent
constructor:
Intent intent = new Intent("com.my.service.project", "com.my.service.project.MyService");
Or add a BroadcastReceiver
to the com.my.service.project
project which then is triggered from the client application by a sendBroadcast
instead of startService
.
Upvotes: 1
Reputation: 13815
NO
At least As Far as I Know. You need to declare it in the manifest for it to be active.
You can register receivers programatically . That you can google out.
Upvotes: 0