title: Android Service can be bind without start?
body: <p>In many articles, tutorials, docs, have read so far, that we call startService() or bindService(), both starts the service. We can call both also, but that's a different story. I am unable to bindService without startService(). </p>
  
  <pre><code>    private void bindTunManagerService(int flags) {
      TunnelManagerService.setParentActivity(this);
      Intent bindIntent = new Intent(this, TunnelManagerService.class);
      startService(bindIntent);
      tunManagerServiceStarted = bindService(bindIntent, tunConnection, BIND_AUTO_CREATE);
  
      Log.d(TAG, "tunManagerServiceStarted  : " + tunManagerServiceStarted + ", ** tunManagerService = " + tunManagerService );
  </code></pre>
  
  <p>In the above code, if I comment startService(), bindService returns false and tunManagerService = null, even onServiceConnected is not fired up and I get "Unable to sart service intent {...} not found" message. After adding startService, service's onCreate, onStart, onServiceConnected are called and is successfully bounded.  </p>
  
  <p>In practical usage, is it necesary to first startServie &amp; then only we can bindService(). It implies that without startSErvice, we can't bindService !! If this statement is wrong, why I can't bindService without starting it ?</p>
  
  <p>Any ideas ????</p>
  
  <p><strong>CODE ADDED</strong></p>
  
  <p><strong>ServiceConnection :</strong></p>
  
  <pre><code>    private ServiceConnection tunConnection = new ServiceConnection() {
  
      @Override
      public void onServiceConnected(ComponentName name, IBinder service) {
          Log.d(TAG,"onServiceConnected" );
          tunManagerService = ITunnelManagerService.Stub.asInterface(service);
          doConnect();
      }
  
      @Override
      public void onServiceDisconnected(ComponentName name) {
          Log.d(TAG,"onServiceDisconnected" );
          tunManagerService = null;
      }
  
  };
  </code></pre>
  
  <p><strong>Service :</strong></p>
  
  <pre><code>public class TunnelManagerService extends Service {
  @Override
  public IBinder onBind(Intent arg0) {
      return binder;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
      Log.d(TAG, "TunnelManagerService: onCreate");
      setCreatedPreference(true);
      notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
      Log.i(TAG, "Received start id " + startId + ": " + intent);
      return START_STICKY;
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
      setCreatedPreference(false);
      hideNotifConnected();
      Log.d(TAG, "TunnelManagerService: onDestroy");
  }
  
  private final ITunnelManagerService.Stub binder = new ITunnelManagerService.Stub() {
    // contains all methods
  }
  
  ...............
  .............
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Manifest :</strong></p>
  
  <pre><code>        &lt;activity android:name=".StartUltimate" android:label="@string/app_name" 
           android:launchMode="singleTask" android:windowSoftInputMode="stateHidden|adjustResize"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;service android:name="orange.android.vpn.utilities.TunnelManagerService" android:enabled="true"&gt;&lt;/service&gt;
  </code></pre>
  
  <p>I use 2.3.3 SDK i.e. API 10. My activity from which I am calling is in "orange.android.vpn" and the service related files are in "orange.android.vpn.utilities" packages respectively.</p>