title: Launching Twitter intent on Android not always new tweet
body: <p>I've got this code (below) which launches the official Twitter app (provided the user has the app installed) and goes straight to a new tweet containing some predefined text. </p>
  
  <p>This works ok when the twitter app has not been launched previously or has been exited using the hard back button, however there is some random (for lack of a better word) behaviour with this which seems to dependant on the users activity within the official twitter app. If the user has been viewing the various tabs with on the twitter app and then changes to my app by either pressing the home button and launching or using the long hold press method, my intent just launches to the last twitter screen they were viewing and doesn't always launch to write a new tweet post.</p>
  
  <p>Is there any way this can be avoided, or is my code inherently set up for this type of behaviour and how would I go about altering it?</p>
  
  <pre><code>public void launchTwitter() {
          Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
          shareIntent.setType("text/plain");
          shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Some text");
          shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, getString(R.string.twittertext));
          final PackageManager pm = this.getPackageManager();
          final List&lt;ResolveInfo&gt; activityList = pm.queryIntentActivities(shareIntent, 0);
          int count = 0;
          for (final ResolveInfo app : activityList) {
              count++;
              if (app.activityInfo.name.equals("com.twitter.android.PostActivity")) {//"com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
                  final ActivityInfo activity = app.activityInfo;
                  final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                  shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                  shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                  shareIntent.setComponent(name);
                  startActivity(shareIntent);
                  break;
              }
              else if(count == activityList.size()) {
                  Toast.makeText(Home.this, "No suitable Twitter apps found.",
                          Toast.LENGTH_SHORT) .show();
                  break;              
                  }
          }
  }
  </code></pre>