Reputation: 33511
I create an app, with two flavors, "full" and "demo". Both define and start a service with a non-cancelable Notification
. When I both start "full" and "demo", the service is started twice, which clogs the notification bar.
The service is started like this:
startService(new Intent(this, MyService.class));
Is there a way to not start the service if it was already started by the 'other' app?
Upvotes: 2
Views: 49
Reputation: 4112
You can manage it in ways :
true
in both of your app Upvotes: 0
Reputation: 1268
You should configure your demo app not to start the service by disabling it in the manifest android:enabled=["true" | "false]"
and then define your service as exported android:exported=["true" | "false]"
so that it can also be started by your demo app. This way it can be started by both but instantiated only in the full version.
If you want the demo app to also be able to run as a standalone app, you should probably do something different. Check if the service is running already before starting it:
ActivityManager manager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
for ( RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("your.package.name".equals(service.service.getClassName())) {
return true;
}
Upvotes: 2