@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
      case REQUEST_ACCOUNT_PICKER:
        if (resultCode == RESULT_OK) {
          String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
          PrefsManager.setLoggedInAccountEmail(getApplication(), accountName);

          connectionProgress.show();
          if (!Constants.LOCAL_RUN) {
            initializeApiClient(accountName);
            apiClient.connect();
          }
        }
        break;

      case REQUEST_CODE_RESOLVE_ERR:
        if (resultCode == RESULT_OK) {
          connectionResult = null;
          if (!Constants.LOCAL_RUN) apiClient.connect();
        }

        break;

      case REQUEST_RECOVER_AUTH:
        Log.d("TAG", "Recover Auth");
        break;
    }
  }
  /** @return credential used to access App Engine API */
  public GoogleAccountCredential getGoogleAccountCredential() throws NullPointerException {

    if (Constants.LOCAL_RUN) {
      return null;
    }

    GoogleAccountCredential credential =
        GoogleAccountCredential.usingAudience(this, Constants.ANDROID_AUDIENCE);
    String loggedInAccount = PrefsManager.getLoggedInEmail(getApplication());

    if (loggedInAccount == null) {
      // App Should crash if activity wants a credential and user is not logged in
      throw new NullPointerException("Not Logged In");
    }

    credential.setSelectedAccountName(loggedInAccount);

    return credential;
  }
  @Override
  protected void onStart() {
    super.onStart();

    if (!(this instanceof LoginActivity)
        && !(this instanceof NewAccountActivity)
        && ZeppaUserSingleton.getInstance().getUserMediator() == null) {
      Intent toLogin = new Intent(this, LoginActivity.class);
      startActivity(toLogin);
      finish();
    }

    ((ZeppaApplication) getApplication()).setCurrentActivity(this);

    String heldAccountName = PrefsManager.getLoggedInEmail(getApplication());
    if (!Constants.LOCAL_RUN && heldAccountName != null && !heldAccountName.isEmpty()) {
      initializeApiClient(heldAccountName);
      apiClient.connect();
    }
  }