title: Activity not rebinding to foreground service after onResume
body: <p>I have an activity which I use to launch a foreground service which continues to run in the background, even when the activity is closed.  I bind to this service since I want to re-use the same service when the activity is stopped and resumed.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>//Service button click listener
  startSvcButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
  
          stopService(new Intent(MainActivity.this, ForegroundService.class));
          startService(new Intent(MainActivity.this, ForegroundService.class));
          bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
          moveTaskToBack(true);
  
      }
  });
  </code></pre>
  
  <p>In the service class the service is started as follows:
  ForegroundService.java</p>
  
  <pre><code>startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, serviceNotification);
  return Service.START_STICKY;
  </code></pre>
  
  <p>The problem I have is that when the <code>MainActivity</code> is stopped, <code>unBind</code> is called, which is good, but when I resume the <code>MainActivity</code> and call <code>bindService</code> again, it never happens. </p>
  
  <p>The foreground service is running, I call <code>bindService</code> again from the <code>onResume</code> of the activity but <code>mBound</code> and <code>mService</code> stays null, even when I accommodate the <code>async bindService</code> (I know the while loop is not good but it is for debugging)
  The <code>serviceConnection</code> is ok.</p>
  
  <p>MainActivity.class:</p>
  
  <pre><code>if (fsRunning) {
      if (!mBound) {
          bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
      }
      do {
          SystemClock.sleep(500);
  
      } while (!mBound);
  
  }
  </code></pre>
  
  <p>How do I get the foreground service to rebind to <code>MainActivity</code> after on <code>onStop</code> of the activity and triggering a <code>new bindService</code>?</p>