title: Foreground Service killed and not restarted
body: <p>I have developed an app with Android BLE (bluetooth low enbergy)
  It is working fine but when Android require more memory, my service is killed.</p>
  
  <ul>
  <li><p>I am using a foreground service with a separate process.</p>
  
  <p>&lt; receiver android:name=".BluetoothLeService$MyReceiver"/></p>
  
  <p>&lt; service android:name=".BluetoothLeService"
          android:enabled="true"
          android:exported="true"
          android:process=":myservice"/></p></li>
  </ul>
  
  <p>I start my service from activity as:</p>
  
  <pre><code> startService(new Intent(this, BluetoothLeService.class));
  </code></pre>
  
  <p>and in my service:</p>
  
  <pre><code>    @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      SetNotification(0);
      return START_STICKY;
  }
  </code></pre>
  
  <p>but when my service got killed by OS, it doesn't restart.
  I have tried closing all recent app but not getting any solution.... </p>
  
  <p>Is there any solution for this? Please help me. Any help will be appreciated. Thank you in advance.</p>
  
  <p>--- Poweramp app isn't never killed --- why?</p>
  
  <p>EDIT:</p>
  
  <p>MainActivity in OnCreate:</p>
  
  <pre><code>...
                  startService(new Intent(this, BluetoothLeService.class));
  </code></pre>
  
  <p>In BluetoothLeService:</p>
  
  <pre><code> @Override
  public void onDestroy() {
      unregisterReceiver(mReceiver); // receiver for bt on and bt off
      super.onDestroy();
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      SetNotification(0);
      return START_STICKY;
  }
  
      @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  
  public void SetNotification(int VerdeRosso){
  
      if (VerdeRosso == 1) { // connected
          remoteViews = new RemoteViews(getPackageName(), R.layout.notification_connesso);
      }else {
          remoteViews = new RemoteViews(getPackageName(), R.layout.notification_disconnesso);
      }
      mBuilder = new NotificationCompat.Builder(getApplicationContext());
      mBuilder.setContent(remoteViews);
      mBuilder.setSmallIcon(R.mipmap.ic_launcher);
      startForeground(123, mBuilder.build()); // 123 è l'id a caso
  }
  
     @Override
  public void onCreate() {
  
  
      mBluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
      mBluetoothAdapter = mBluetoothManager.getAdapter();
  
      //broadcaster = LocalBroadcastManager.getInstance(this);
  
      IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
      mReceiver = new MyReceiver();
  
      registerReceiver(mReceiver, filter);
      scanLeDevice(true);
  
  }
  </code></pre>
  
  <p>--- EDIT 2</p>
  
  <pre><code>    private final IBinder myBinder = new LocalBinder();
  
  public class LocalBinder extends Binder {
      BluetoothLeService getService() {
          return BluetoothLeService.this;
      }
  }
  ....
      @Override
  public IBinder onBind(Intent intent) {
  
      return myBinder;
  }
  </code></pre>