title: Simple service won't bind : bindService return false, service connection never triggered
body: <p>This is my first time using Service in Android and my service won't bind.</p>
  
  <p>The Service code :</p>
  
  <pre><code>package mackosoft.almightymessage;
  public final class MainService extends Service {
      private final static String TAG = "Main Service";
      private final IBinder binder = new MainServiceBinder();
  
      @Override
      public final void onCreate() {
          super.onCreate();
          Log.d(TAG, "Service created");
          Toast.makeText(this, "Service created", Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public final int onStartCommand(final Intent intent, final int flags, final int startId) {
          return START_STICKY;
      }
  
  
      @Override
      public final void onDestroy() {
          super.onDestroy();
          Log.d(TAG, "Service created");
          Toast.makeText(this, "Service destroyed", Toast.LENGTH_SHORT).show();
      }
  
  
      @Override
      public final IBinder onBind(final Intent intent) {
          Toast.makeText(this, "Service binded", Toast.LENGTH_SHORT).show();
          return this.binder;
      }
  
  public final class MainServiceBinder extends Binder {
          final MainService getService() {
              return MainService.this;
          }
      }
  }
  </code></pre>
  
  <p>Manifest file :</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="mackosoft.almightymessage" &gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_logo"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;activity
          android:name=".MainActivity"
          android:configChanges="orientation|keyboardHidden"
          android:icon="@drawable/ic_logo"
          android:label="@string/app_name"
          android:screenOrientation="portrait" &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=".MainService"
          android:enabled="true" &gt;
      &lt;/service&gt;
  
  &lt;/Application
  &lt;/manifest&gt;
  </code></pre>
  
  <p>And finally the part in MainActivity where I try to bind the service :</p>
  
  <pre><code>public final class MainActivity extends AppCompatActivity {
  @Override
  protected final void onStart() {
          super.onStart();
          final Intent intent = new Intent(MainActivity.this, MainService.MainServiceBinder.class);
          final boolean status = bindService(intent, this.connection, Context.BIND_AUTO_CREATE);
          Log.d(TAG, "Service binded ? " + status);
      }
  
   private final ServiceConnection connection = new ServiceConnection() {
          @Override
          public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
              Log.d(TAG, "Service connected !");
              service = ((MainService.MainServiceBinder) iBinder).getService(); // service is a private member of MainActivity
          }
  
          @Override
          public void onServiceDisconnected(ComponentName componentName) {
              Log.d(TAG, "Service disconnected !");
          }
      };
  }
  </code></pre>
  
  <p>Running the application, Logcat shows : </p>
  
  <p><code>mackosoft.almightymessage D/MainActivity﹕ Service binded ? false</code></p>
  
  <p>And Service Connection is NEVER triggered !</p>
  
  <p>I tried multiple solution :</p>
  
  <ol>
  <li>Moving the binding call to a <code>Button.onClick()</code> and using <code>getApplicationContext()</code></li>
  <li>Using directly <code>getApplicationContext()</code></li>
  <li>In the Manifest, changed -> <code>android:name="mackosoft.almightymessage.MainService"</code></li>
  <li>Changed also the <code>Intent</code>-> <code>final Intent intent = new Intent(this, MainService.MainServiceBinder.class);</code></li>
  <li>Also tried to add <code>this.startService(intent)</code> and with <code>this.getApplicationContext()</code></li>
  </ol>
  
  <p>All of the above fail and no error in the logs !</p>
  
  <p>I have no luck at all.</p>
  
  <p>Test device : Samsung Galaxy Note 3 running Cyanogen Mode 12.1 (Android 5.1)</p>
  
  <p>Android Studio 1.2.1.1 (stable)</p>
  
  <p>Thanks for the help !!</p>