title: Instantiating a View on non-UI thread
body: <p>I know that the UI elements (View hierarchy) may only be manipulated from the UI thread. For a background operation, the AsyncTask can be used, which offers event handlers to reach the UI thread.</p>
  
  <p>To be brief, is it allowed to instantiate a View (tied to <code>getApplicationContext()</code>) in a non-UI thread? This custom View descendant -- once instantiated -- is added to the view hierarchy from <strong>the UI thread</strong>. So only the constructor call is done inside an <code>Asynctask.doInBackground()</code>; it's attaching (<code>addView(...)</code>) to the Activity's root layout hierarchy is still done in the UI thread.</p>
  
  <p>In details:</p>
  
  <pre><code>public MyView extends View {
       public MyView(Context context) { 
              ...
       }
  ...
  }
  </code></pre>
  
  <ol>
  <li><p>I made a custom View, with overriden <code>onDraw(...)</code> etc.</p></li>
  <li><p>When the user clicks a certain MenuItem in my main Activity, another Activity (MyOtherActivity) is created and displayed <strong>which screen is exactly MyView</strong></p></li>
  <li><p>Since the screen of MyOtherActivity must be displayed instantly, I pre-instantiate MyView in an AsyncTask while the user is somewhere else in the main Activity (i.e. he hasn't clicked that MenuItem yet). The MyView reference is stored in a static data member.</p></li>
  <li><p>When <code>MyOtherActivity.onCreate()</code> is called, its constructor code takes MyView from the static, and adds it to its layout root hierarchy via <code>addView(...)</code>.</p></li>
  <li><p>(I'm aware that the static variable may introduce memory leaks, so I set it to <code>null</code> once it's not needed.)</p></li>
  </ol>
  
  <p>Isn't it a problem (and might it introduce unexpected issues) that MyView is instantiated in a different thread (and takes the return value of <code>getApplicationContext()</code> in its constructor)?</p>