title: Gmail API Android `Quickstart` hits a brick wall
body: <p>The <a href="https://developers.google.com/gmail/api/quickstart/android" rel="nofollow noreferrer">google demo</a> makes a single API request. I have tried to use this code as the basis for a more real world scenario (multiple different API calls) but keep hitting a brick wall. The demo's structure makes it very difficult.</p>
  
  <p>Consider the code that makes the API request:</p>
  
  <pre><code>private void getResultsFromApi() {
      if (! isGooglePlayServicesAvailable()) {
          acquireGooglePlayServices();
      } else if (mCredential.getSelectedAccountName() == null) {
          chooseAccount();
      } else if (! isDeviceOnline()) {
          mOutputText.setText("No network connection available.");
      } else {
          new MakeRequestTask(mCredential).execute();
      }
  }
  </code></pre>
  
  <p><code>getResultsFromApi()</code> does a lot of auth stuff before the API request. Should this be done before every API request??</p>
  
  <p><code>getResultsFromApi()</code> may start an activity (in chooseAccount())which means that the <code>onActivityResult()</code> will (re)call <code>getResultsFromApi()</code> in order to eventually get to the API request.</p>
  
  <p>In fact there are actually 5 calls to <code>getResultsFromApi()</code> in the code which together achieve the auth for the single API request!! It may be necessary but it ends up being spaghetti.</p>
  
  <p>This makes the demo impossible to generalize in its current form. Say I want a 2nd button making some other API request. Cant be done without a major rewrite</p>
  
  <p>Can anyone suggest how I can reorganise the demo code in order to make it useable in the real world?</p>
  
  <p>Thanks</p>