title: How to share a service across multiple applications and check if it already running?
body: <p>My problem is that I want to make an SDK (Library project to be included in different app projects) with an IntentService in it. This intent service is scheduled with the AlarmManager to repeat every 2 seconds(in reality this will be every 2 minutes):</p>
  
  <pre class="lang-java prettyprint-override"><code>Intent startServiceIntent = new Intent("com.my.package.MY_UNIQUE_ACTION");
  startServiceIntent.setClass(context, InstalledAppsService.class);
  
  PendingIntent pendingIntent = PendingIntent.getService(context, 0, startServiceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
  AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 2000, 2000, pendingIntent);
  </code></pre>
  
  <p>So when I use this method from the app which started the service:</p>
  
  <pre class="lang-java prettyprint-override"><code>private boolean isMyServiceRunning() {
      Intent startServiceIntent = new Intent("com.my.package.MY_UNIQUE_ACTION");
      startServiceIntent.setClass(context, InstalledAppsService.class);
      boolean alarmUp = (PendingIntent.getService(context, 0,
              startServiceIntent,
              PendingIntent.FLAG_NO_CREATE) != null);
  
      return alarmUp;
  }
  </code></pre>
  
  <p>it returns true if the service is scheduled. I do not want to have the same service started from different apps with the same SDK. I want one service for all apps with the SDK and I only need to check if this service is running from each app.</p>
  
  <p>But when I use this same method but from a different app it returns false.
  This is my manifest:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;service
      android:name="com.test.services.InstalledAppsService"
      android:exported="true"
      android:process="com.test.InstalledAppsService"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="com.my.package.MY_UNIQUE_ACTION" /&gt;
      &lt;/intent-filter&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>Should I add something to the manifest or use the ActivityManager to check if the process is there? Currently I get two log tags from two different services. </p>
  
  <p>What I want is to: Start service, do the job, dispose service. I don't need it to run always. And currently the alarm manager does that but with separate processes.</p>
  
  <p>This is my service:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class InstalledAppsService extends IntentService {
  
      private static final String TAG = "services.InstalledAppsService";
  
      public InstalledAppsService() {
          super("InstalledAppsService");
      }
  
      protected void onHandleIntent(Intent intent) {
      }
  
      public void onCreate() {
          super.onCreate();
      }
  
      public void onDestroy() {
          super.onDestroy();
      }
  }
  </code></pre>