title: Android: Activity to Activity, 2nd activity cannot call setContentView?
body: <p>I have activity 1 (A1) going into activity 2 (A2) and am getting crashes at the setContentView in A2. A1 is a ListActivity that pulls the list from xml and uses an Intent to pass data to be displayed in A2 (putExtra). A2 pulls in xml and uses the Extra data from A1 to know what to display, but my setContentView line crashes the app.</p>
  
  <p>Looking into possible solutions I've read that setContentView must be called from a UI thread; is my A2 not a UI thread?</p>
  
  <p>Code:</p>
  
  <h2>-- A1 --</h2>
  
  <pre><code>public class activity extends ListActivity {
  /** Called when the activity is first created. */
  public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      //setContentView(R.layout.main);
      String[] rmenu = getResources().getStringArray(R.array.root_menu);
      if (rmenu != null) {
          setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, rmenu));
      }
  }
  @Override
      protected void onListItemClick(ListView l, View v, int position, long id) {
          super.onListItemClick(l, v, position, id);
          // Get the item that was clicked
          //Object o = this.getListAdapter().getItem(position);
          //String keyword = o.toString();
          //Toast.makeText(this, "You selected: " + position,     Toast.LENGTH_LONG).show();
          //
          Intent myIntent = new Intent(v.getContext(), Activity1.class);
      myIntent.putExtra("com.activity.Key", position);
      startActivity(myIntent);
      }
  }
  </code></pre>
  
  <h2>-- A2 --</h2>
  
  <pre><code>public class Activity1 extends activity {
  
  /** Called when the activity is first created. */
      @Override
  public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      //setContentView(R.layout.main2);
      int data = 0;
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
          data = extras.getInt("com.activity.Key");
      } else {
          data = 0;
      }
      String[] con = getResources().getStringArray(R.array.content);
      //Toast.makeText(context, con[data], Toast.LENGTH_SHORT).show();
      TextView tv = new TextView(this);
      String dis = con[data];
      tv.setText(dis);
      setContentView(tv);
  }
  }
  </code></pre>
  
  <p>I've read the docs on Activities and ContentViews but they don't do the best job of explaining what cannot be done. Am I tripping over my own feet here?</p>
  
  <p>Manifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.activity"
    android:versionCode="1"
    android:versionName="1.0"&gt;
  &lt;uses-sdk android:minSdkVersion="4" /&gt;
  
  &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:name=".activity" android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
  
      &lt;/activity&gt;
      &lt;activity android:name=".Activity1" android:label="@string/app_name"&gt;    &lt;/activity&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>