title: GoogleApiClient onConnected event is not triggered from from stand alone module
body: <p>I'm new to <code>JAVA</code> and <code>ANDROID</code> and tried to build an app to have the location as per <a href="https://developer.android.com/training/location/retrieve-current.html" rel="nofollow noreferrer">this</a>, so I wrote the below <code>helper</code> code:</p>
  
  <pre><code>package oryx.tecna.locateme;
  
  import android.Manifest;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.location.Location;
  import android.os.Build;
  import android.os.Bundle;
  import android.support.annotation.NonNull;
  import android.support.annotation.Nullable;
  import android.support.v4.app.ActivityCompat;
  import android.widget.Toast;
  
  import com.google.android.gms.common.ConnectionResult;
  import com.google.android.gms.common.api.GoogleApiClient;
  import com.google.android.gms.location.LocationServices;
  
  public class UtilLocation
          implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
  
      protected static GoogleApiClient mGoogleApiClient;
      protected static Location mLastLocation;
  
      public UtilLocation(Context context) {
          mGoogleApiClient = new GoogleApiClient.Builder(Oryx.getContext())
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .build();
      }
  
      @Override
      public void onConnected(@Nullable Bundle bundle) {
          if (ActivityCompat.checkSelfPermission(Oryx.getContext(),
                  Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                  &amp;&amp; ActivityCompat.checkSelfPermission(Oryx.getContext(),
                  Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              return;
          }
          mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
          if (mLastLocation == null)
              Toast.makeText(Oryx.getContext(), R.string.no_location_detected, Toast.LENGTH_LONG).show();
          else
              Toast.makeText(Oryx.getContext(), "Location found", Toast.LENGTH_LONG).show();
      }
  
      @Override
      public void onConnectionSuspended(int i) {
          Toast.makeText(Oryx.getContext(), "Connection suspended", Toast.LENGTH_SHORT).show();
          mGoogleApiClient.connect();
      }
  
      @Override
      public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
          Toast.makeText(Oryx.getContext(), "Connection failed: ConnectionResult.getErrorCode() = "
                  + connectionResult.getErrorCode(), Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  
  <p>I created the below to to get the <code>context</code>:</p>
  
  <pre><code>package oryx.tecna.locateme;
  
  import android.app.Application;
  import android.content.Context;
  
  public class Oryx extends Application {
  
      private static Context mContext;
  
      @Override
      public void onCreate() {
          super.onCreate();
          mContext = getApplicationContext();
      }
  
      public static Context getContext() {
          return mContext;
      }
  }
  </code></pre>
  
  <p>Then I tried to call the above <code>helper</code> using the below code:</p>
  
  <pre><code>location = (new UtilLocation(context)).mLastLocation;
  </code></pre>
  
  <p>but the app had been crashed :(</p>
  
  <p>What is the mistake I did  and how to get it fixed? thanks</p>
  
  <p><strong>UPDATE</strong>
  I found one error, so i replaced the:</p>
  
  <pre><code>mGoogleApiClient = new GoogleApiClient.Builder(Oryx.getContext())
  </code></pre>
  
  <p>by:</p>
  
  <pre><code>mGoogleApiClient = new GoogleApiClient.Builder(context)
  </code></pre>
  
  <p>The app now is not crashing, but not returning the location, i.e. the <code>mLastLocation</code> is read as `nullذ</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>Apparantly, </p>
  
  <pre><code>public void onConnected(@Nullable Bundle bundle)
  </code></pre>
  
  <p>is not executed as none of the Toast appears, neither the one telling there is GPS, nor the one telling there is no GPS</p>