title: MediaBrowserCompat.ConnectionCallback.onConnected() is not being called after connect()
body: <p>I'm creating a player app for android and want to access <code>MediaControllerCompat</code> from any UI class. For this purpose I use <code>MediaBrowserCompat</code> class, I'm trying to connect it to my <code>MediaBrowserServiceCompat</code> and get <code>MediaControllerCompat</code> with <code>MediaSessionCompat.Token</code>, already set in my <code>Service</code>.</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/46121952/mediabrowsercompat-connect-never-calls-onconnected-or-any-mediabrowsercompat-c">MediaBrowserCompat.connect() never calls onConnected or any MediaBrowserCompat.ConnectionCallback method</a> solution, but it didn't help.</p>
  
  <p>TortoiseActivity.java</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_tortoise);
  
          mediaBrowser = new MediaBrowserCompat(
                  TortoiseActivity.this,
                  new ComponentName(TortoiseActivity.this, Service.class),
                  new MediaBrowserCompat.ConnectionCallback() {
                      @Override
                      public void onConnected() {
                          try {
                              MediaSessionCompat.Token token = mediaBrowser.getSessionToken();
                              MediaControllerCompat controller = new MediaControllerCompat(TortoiseActivity.this, token);
                              MediaControllerCompat.setMediaController(TortoiseActivity.this, controller);
                          } catch (RemoteException e) {
                              e.printStackTrace();
                          }
                      }
  
                      @Override
                      public void onConnectionFailed() {
                          Log.e("TAG", "onConnectionFailed");
                      }
  
                      @Override
                      public void onConnectionSuspended() {
                          Log.e("TAG", "onConnectionSuspended");
                      }
                  },
                  null);
          mediaBrowser.connect();
      }
  </code></pre>
  
  <p>Service.java</p>
  
  <pre><code>    @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return mBinder;
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
  
          mediaSession = new MediaSessionCompat(this, Service.class.getSimpleName());
          setSessionToken(mediaSession.getSessionToken());
  
          mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
          mediaSession.setActive(true);
  
          mediaSession.setCallback(callback);
      }
  </code></pre>
  
  <p>SmallPlayerFragment.java</p>
  
  <pre><code>void initControls(Activity context) {
          MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(context);
          this.transportControls = mediaController.getTransportControls();
      }
  </code></pre>
  
  <p>As a result, I get NullPointer</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.media.session.MediaControllerCompat$TransportControls android.support.v4.media.session.MediaControllerCompat.getTransportControls()' on a null object reference
          at ru.krivocraft.kbmp.SmallPlayerFragment.initControls(SmallPlayerFragment.java:49)
          at ru.krivocraft.kbmp.TortoiseActivity.getSmallPlayerFragment(TortoiseActivity.java:122)
          at ru.krivocraft.kbmp.TortoiseActivity.showSmallPlayerFragment(TortoiseActivity.java:248)
          at ru.krivocraft.kbmp.TortoiseActivity.access$200(TortoiseActivity.java:31)
          at ru.krivocraft.kbmp.TortoiseActivity$4.onItemClick(TortoiseActivity.java:109)
  </code></pre>
  
  <p>when trying to get <code>MediaControllerCompat.TrasportControls</code>. <code>MediaControllerCompat</code> is, definitely, null. I set breakpoint in Callback's onConnected(), but thread doesn't suspend on it. So, i can conclude, that callback is not being called.</p>