code: private void getCredentials(final String code) {
          new AsyncTask<Void, Void, Boolean>() {
              @Override
              protected Boolean doInBackground(Void... params) {
                  try {
                      mBootstrapper.getUserCredentials(code);
                      return true;
  
                  } catch (IOException ex) {
                      LOGGER.error("Error getting oauth credentials", ex);
                      setResult(RESULT_CANCELED);
                      finish();
  
                  } catch (CStorageException ex) {
                      LOGGER.error("Error getting oauth credentials", ex);
                      setResult(RESULT_CANCELED);
                      finish();
                  }
                  // Failure
                  return false;
              }
  
              @Override
              protected void onPostExecute(Boolean result) {
                  if(result) {
                      setResult(RESULT_OK);
                  } else {
                      setResult(RESULT_CANCELED);
                  }
                  finish();
              }
          }.execute();
      }
docs: Gets user credentials and save them
  If OK, set result OK and come back to calling activity
  
  @param code The code used to retrieve the OAuth access token