title: Use a service and binder from a library project
body: <p>I'm currently working on a radio <strong>streaming</strong> application.
  To do the work i decided to create a <strong>Library project</strong> to do some <strong>code refactoring</strong></p>
  
  <p>So in my Library project i have : </p>
  
  <ul>
  <li>StreamingService.java</li>
  <li>StreamingPlayerMP.java</li>
  <li>StreamingPlayerAAC.java</li>
  <li>StreamingCallback.java</li>
  <li>StreamingNotification.java</li>
  <li>StreamingState.java</li>
  <li>StreamingStation.java</li>
  </ul>
  
  <p>Do i need to define the service in both the <strong>library manifest</strong> and the <strong>application Manifest</strong> ?</p>
  
  <pre><code>   &lt;service
          android:name=".StreamingService"
          android:enabled="true" &gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>Do i need to put permissions in both the <strong>library manifest</strong> and the <strong>application Manifest</strong> too ?</p>
  
  <p>Currently the Service/players/callback are <strong>ready for use</strong>. I want to manage the service with a <strong>ServiceConnection</strong> and a <strong>binder</strong> to the main activity :</p>
  
  <pre><code>public void bindToService() {
  
      Intent intent = new Intent(getApplicationContext(), StreamingService.class);
      if (((TestingApplication) getApplication()).MediaPlayerServiceRunning()) {
          Log.i(TAG, "bindToService--");
          // Bind to LocalService
          bindService(intent, _connectionStreaming, Context.BIND_AUTO_CREATE);
      }
      else {
          Log.i(TAG, "bindToService--startService--");
          startService(intent);
          boolean isBound = bindService(intent, _connectionStreaming, Context.BIND_AUTO_CREATE);
          Log.d(TAG, "IS SERVICE BOUND--" + isBound);
      }
  }
  
  private ServiceConnection   _connectionStreaming    = new ServiceConnection() {
                                                              @Override
                                                              public void onServiceConnected(ComponentName className, IBinder serviceBinder) {
  
                                                                  Log.d(TAG, "onServiceConnected--");
                                                                  // service
                                                                  MediaPlayerBinder binder = (MediaPlayerBinder) serviceBinder;
                                                                  TestingApplication._mediaPlayerService = binder.getServiceInstance();
                                                                  // callback
                                                                  TestingApplication._mediaPlayerService.setInitCallBack(MainActivity.this);
                                                                  TestingApplication._mediaPlayerService.initializePlayer(getString(R.string.url_podcast_mp3_test));
                                                                  _bound = true;
                                                              }
  
                                                              @Override
                                                              public void onServiceDisconnected(ComponentName arg0) {
  
                                                                  Log.d(TAG, "onServiceDisconnected--");
                                                                  _bound = false;
                                                              }
                                                          };
  </code></pre>
  
  <p>And the binder methods (located in the service):</p>
  
  <pre><code>private final Binder                    _binder         = new MediaPlayerBinder();
  
  public class MediaPlayerBinder extends Binder {
      public StreamingService getServiceInstance() {
  
          Log.i(TAG, "getServiceInstance--");
          return StreamingService.this;
      }
  }
  
  @Override
      public IBinder onBind(Intent arg0) {
  
          Log.i(TAG, "onBind--");
          return _binder;
      }
  </code></pre>
  
  <p>The service is a foregroundservice : </p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      Log.i(TAG, "onStartCommand--");
      _runningCallBack.onBufferingStarted();
      return START_STICKY;
  }
  </code></pre>
  
  <p>If you have a complete solution you are welcome !
  Advices are welcome too</p>