title: peekService() returns null even though the service is running, if the service is restarted by the system after OOM kill
body: <p>I'm starting a service using</p>
  
  <pre><code>startService(new Intent(this, RelayService.class));
  </code></pre>
  
  <p>and then the service starts an alarm using</p>
  
  <pre><code>AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  Intent intent = new Intent(this, SyncAlarmReceiver.class);
  PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent,
      PendingIntent.FLAG_CANCEL_CURRENT);
  am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
      SystemClock.elapsedRealtime() + SYNC_EVERY_MS, SYNC_EVERY_MS, pi);
  </code></pre>
  
  <p>and then BroadcastReceiver <code>SyncAlarmReciver</code> is trying to get the service using</p>
  
  <pre><code>RelayServiceBinder relay = (RelayServiceBinder) 
      peekService(context, new Intent(context, RelayService.class));
  </code></pre>
  
  <p>It all works fine until the service is restarted by the system after application gets killed when other applications need more memory. After restart, the service relaunches the alarm using the same code, but <code>peekService()</code> returns null. Through debugging messages, I see that <code>context</code> in the service and in the broadcast receiver is the same, as well as RelayService object, i.e. these objects are the same objects in memory. How can I solve this problem?</p>
  
  <p>If it helps, here are links to the three pieces of the code mentioned: <a href="https://github.com/oakkitten/weechat-android/blob/sync/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/WeechatActivity.java#L107" rel="nofollow">main activity</a>, <a href="https://github.com/oakkitten/weechat-android/blob/sync/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/RelayService.java#L110-L113" rel="nofollow">service</a>, <a href="https://github.com/oakkitten/weechat-android/blob/sync/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/SyncAlarmReceiver.java#L12" rel="nofollow">broadcast receiver</a>.</p>
  
  <p>P.S. I know that <strong>the service is running continuosly</strong> because I'm watching the process closely and see it running fine and not restarting in any way, and also because I see that connection it opens before launching the alarm does not get interrupted.</p>