title: Using Android ProgressDialog with AsyncTask and odd Activity Lifecycle
body: <p>I couldn't think of a way to form my title to make my issue obvious, so here goes:</p>
  
  <p>I'm a little over my head with diving into AsyncTask for the first time. I currently have an app that simply sends a tweet. To do this it must kick out to a WebView for Twitter authorization, which comes back to onNewIntent().</p>
  
  <p>What I'm trying to do is throw up a simple Spinner ProgressDialog while it's connecting to the site/performing the AccessToken work, and then again while it's sending the tweet. I've only just discovered that I will need a new thread for the progress bar. Or rather, that I should be doing my "time-intensive work" in it's own separate thread to make using a ProgressDialog viable. My question is this: How can I have my progress spinner in the foreground while my authorization code works in the background, and eventually opens the WebView and comes back, and ultimately starts everything over at onResume()?</p>
  
  <p>I'm sure I'm probably not doing everything else in the most proper fashion. I'm new to Android, but not to Java. I've put in my create- and dismissDialog(int) calls about where they should be, procedurally. As-is, everything otherwise works the way it should, but obviously my dialogs are simply not able show themselves.</p>
  
  <p>I'm thinking I should basically put my entire authorize() and tweet() methods into their own AsyncTask. I'm just not sure how to go about that, especially since authorize() (or more specifically, loginToTwitter()) needs to end up saving the data it gets from the browser to shared preferences after it comes back to onNewIntent().</p>
  
  <p>Thanks for any insights,
  == Matt</p>
  
  <pre class="lang-java prettyprint-override"><code>public class IntegrateTwitter extends Activity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  
          mPrefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
          mTwitter = new TwitterFactory().getInstance(); 
          mTwitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
  
          if(authorize()) {
              tweet();
              returnToMM();
          }
      }
  
      private boolean authorize() {
          Log.i(LOG_TAG, "Authorizing...");   
          showDialog(PD_AUTHORIZING);
          boolean result = false;
  
          if(responseExistsAndValid()) {
              saveResponseToAccessToken();
          }
  
          if(isAuthorized()) {
              Log.i(LOG_TAG, "Prefs have AccessToken, grabbing it...");
              if(getAccessTokenFromPrefs()) {
                  Toast.makeText(IntegrateTwitter.this, "Authorized.", Toast.LENGTH_SHORT).show();
                  result = true;
              }
          }
          else {
              Log.i(LOG_TAG, "Prefs don't have AccessToken.");
  
              if(!responseStringExists()) {
                  Log.i(LOG_TAG, "No response exists either, starting Twitter login process...");
                  Toast.makeText(IntegrateTwitter.this, "Authorizing...", Toast.LENGTH_SHORT).show();
                  // Here is where it kicks out to the browser for authentication
                  loginToTwitter();
              }
              else {
                  Toast.makeText(IntegrateTwitter.this, "Authorization failed.", Toast.LENGTH_SHORT).show();
                  Log.i(LOG_TAG, "Response exists, so it must have failed once already, skipping Twitter login process.");
                  returnToMM();
              }
          }
  
          deleteResponseFromPrefs();
  
          dismissDialog(PD_AUTHORIZING);
          return result;
      }
  
      private void tweet() {
          showDialog(PD_TWEETING);
  
          try {
              Date testDate = new Date();
              String testDateString  = DateFormat.format("yyyy-MM-dd @ hh:mm:ss", testDate.getTime()).toString();
              mTwitter.updateStatus(testDateString + " Test Tweet");
              Toast.makeText(this, "Tweet successful!", Toast.LENGTH_SHORT).show();
          }
          catch (TwitterException e) {
              Toast.makeText(this, "Tweet error.", Toast.LENGTH_SHORT).show();
              Log.i(LOG_TAG, e.getMessage());
              Log.i(LOG_TAG, Arrays.toString(e.getStackTrace()));
          }
  
          dismissDialog(PD_TWEETING);
      }
  
      // A bunch of support methods
      // ...  
  }
  </code></pre>