title: Android ActivityRecognition java.lang.NullPointerException: Appropriate Api was not requested
body: <p>I'm attempting to follow Google's <a href="https://github.com/googlesamples/android-play-location/tree/master/ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition" rel="noreferrer">Activity Recognition</a> example.</p>
  
  <p>In the example they start the activity recognition when you click a button, however I'd like to just start it up when the app starts - so I tried putting it in the <code>onConnected</code> method. However, it ends up throwing a null pointer exception.</p>
  
  <p>Here's how I'm calling it:</p>
  
  <pre><code>@Override
  public void onConnected(Bundle connectionHint) {
      Log.d(TAG, "onConnected");
      try {
          ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(
                  mGoogleApiClient,
                  UPDATE_INTERVAL_IN_MILLISECONDS,
                  getActivityDetectionPendingIntent()
          ).setResultCallback(this);
  
      } catch (SecurityException securityException) {
          logSecurityException(securityException);
      }
  }
  </code></pre>
  
  <p>And the error:</p>
  
  <pre><code>03-21 20:28:57.939    2340-2340/getrewards.example.com.getrewards E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: getrewards.example.com.getrewards, PID: 2340
      java.lang.NullPointerException: Appropriate Api was not requested.
              at com.google.android.gms.internal.jx.b(Unknown Source)
              at com.google.android.gms.common.api.c.a(Unknown Source)
              at com.google.android.gms.common.api.c.a(Unknown Source)
              at com.google.android.gms.common.api.c.b(Unknown Source)
              at com.google.android.gms.internal.nb.requestActivityUpdates(Unknown Source)
              at getrewards.example.com.getrewards.RewardsFragment.onConnected(RewardsFragment.java:274)
              at com.google.android.gms.internal.jm.f(Unknown Source)
              at com.google.android.gms.common.api.c.gJ(Unknown Source)
              at com.google.android.gms.common.api.c.d(Unknown Source)
              at com.google.android.gms.common.api.c$2.onConnected(Unknown Source)
              at com.google.android.gms.internal.jm.f(Unknown Source)
              at com.google.android.gms.internal.jm.dU(Unknown Source)
              at com.google.android.gms.internal.jl$h.b(Unknown Source)
              at com.google.android.gms.internal.jl$h.g(Unknown Source)
              at com.google.android.gms.internal.jl$b.hy(Unknown Source)
              at com.google.android.gms.internal.jl$a.handleMessage(Unknown Source)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  03-21 20:28:58.343    1235-1594/system_process E/ActivityManager﹕ Invalid thumbnail dimensions: 288x288
  03-21 20:29:02.543    1235-1267/system_process E/InputDispatcher﹕ channel '39825fb6 getrewards.example.com.getrewards/getrewards.example.com.getrewards.RewardsActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
  03-21 20:33:31.053    2374-2374/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:33:31.053    2374-2374/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:33:44.213    2403-2403/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:33:44.213    2403-2403/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:34:56.658    2479-2479/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:34:56.659    2479-2479/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:35:09.756    2501-2501/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:35:09.756    2501-2501/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:35:52.821    2563-2563/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:35:52.821    2563-2563/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:35:53.299    1235-1267/system_process E/InputDispatcher﹕ channel '21589154 getrewards.example.com.getrewards/getrewards.example.com.getrewards.RewardsActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
  03-21 20:36:06.753    2586-2586/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:36:06.753    2586-2586/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:36:29.956    2634-2634/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:36:29.956    2634-2634/? E/android.os.Debug﹕ failed to load memtrack module: -2
  03-21 20:36:43.621    2657-2657/? E/memtrack﹕ Couldn't load memtrack module (No such file or directory)
  03-21 20:36:43.621    2657-2657/? E/android.os.Debug﹕ failed to load memtrack module: -2
  </code></pre>
  
  <p>Any ideas what I need to do differently to avoid this error? Other location services work just fine - like geofencing or requesting activity updates.</p>