Code example for FragmentActivity

Methods: getApplicationContext, onResume

0
    mMessageView = (TextView) findViewById(R.id.message_text);
  } 
 
  @Override 
  protected void onResume() { 
    super.onResume(); 
    setUpMapIfNeeded(); 
    setUpLocationClientIfNeeded(); 
    mLocationClient.connect();
  } 
 
  @Override 
  public void onPause() { 
    super.onPause(); 
    if (mLocationClient != null) {
      mLocationClient.disconnect();
    } 
  } 
 
  private void setUpMapIfNeeded() { 
    // Do a null check to confirm that we have not already instantiated the map. 
    if (mMap == null) {
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
             .getMap();
      // Check if we were successful in obtaining the map. 
      if (mMap != null) {
        mMap.setMyLocationEnabled(true);
      } 
    } 
  } 
 
  private void setUpLocationClientIfNeeded() { 
    if (mLocationClient == null) {
      mLocationClient = new LocationClient(
          getApplicationContext(), 
          this,  // ConnectionCallbacks
          this); // OnConnectionFailedListener
    } 
  }