title: MediaBrowser not connecting to MediaBrowserService
body: <p>I'm trying to connect to a MediaBrowserService from an activity using a MediaBrowser. However, my <code>onConnected</code> callback never seems to be called to allow me to set up the <code>MediaController</code> and start manipulating playback.</p>
  
  <p>In my player/browser activity:</p>
  
  <pre><code>private final MediaBrowserCompat.ConnectionCallback mConnectionCallback =
              new MediaBrowserCompat.ConnectionCallback() {
                  @Override
                  public void onConnected() {
                      try {
                          mMediaController =
                                  new MediaControllerCompat(
                                          PlayActivity.this,
                                          mMediaBrowser.getSessionToken()
                                  );
  
                          mMediaController.registerCallback(mControllerCallback);
  
                          mControllerCallback
                                  .onMetadataChanged(mMediaController.getMetadata());
                          mControllerCallback
                                  .onPlaybackStateChanged(mMediaController.getPlaybackState());
                      } catch (RemoteException e) {
                          throw new RuntimeException(e);
                      }
  
                      mMediaController
                              .getTransportControls()
                              .prepareFromUri(
                                      Uri.parse(
                                              getIntent()
                                                      .getStringExtra(StreamingService.STREAM_URI)),
                                      getIntent().getExtras());
  
                      mMediaController
                              .getTransportControls().play();
  
                      buildTransportControls();
                  }
  
                  @Override
                  public void onConnectionSuspended() { }
  
                  @Override
                  public void onConnectionFailed() { }
              };
  
  @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_play);
          setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
          Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
  
          mMediaBrowser = new MediaBrowserCompat(this,
                  new ComponentName(this, StreamingService.class),
                  mConnectionCallback,
                  null);
      }
  
      @Override
      public void onStart() {
          super.onStart();
          mMediaBrowser.connect();
      }
  </code></pre>
  
  <p>I've added breakpoints with the debugger and it seems that execution does reach the service, to the end of its <code>onCreate</code> method, but execution never seems to reach either the <code>onConnected</code> or <code>onConnectionFailed</code> methods of my connection callback. After <code>connect</code> is called, checked <code>isConnected</code> returns false.</p>
  
  <p>I'm not sure how to debug further as the problem is happening somewhere during the connection process, and as far as I can tell my code conforms to Android example guides. And yes I am calling <code>setSessionToken</code> in <code>onCreate</code> of the browser service.</p>
  
  <p>If I try to set up the MediaController in <code>onStart</code> of my activity, after I call <code>connect</code>, I get an exception stating that the browser is not connected and so the session token cannot be set. So although execution goes into <code>onCreate</code> of my service, the connection is not completing.</p>