title: Update UI from AsyncTask and handle properly screen rotate
body: <p>This code doesn't works when rotate screen.
  I try to use Handler but messages are dispached to previous Activity(before rotate) and to new Activity.</p>
  
  <p>¿How can a thread send messages to new Activity?
  Please doesn't suggest avoid to rotate screen. </p>
  
  <pre><code>public class SampleActivity extends Activity {
      TextView text;
      Handler handler;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          LinearLayout layout = new LinearLayout(this);
          layout.setOrientation(LinearLayout.VERTICAL);
          text = new TextView(this);
          text.setText("HELLO");
  
          layout.addView(text);
          if (savedInstanceState != null) {
              text.setText(savedInstanceState.getString("text"));
          }
  
          setContentView(layout);
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          outState.putString("text", text.getText().toString());
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          new CounterTask().execute();
      }
  
      public class CounterTask extends AsyncTask&lt;Void, String, Void&gt; {
  
          @Override
          protected Void doInBackground(Void... params) {
              for (int i = 0; i &lt; 100; i++) {
                  try {
                      Thread.sleep(100);
                      publishProgress("Hello " + i);
                  } catch (Exception e) {
  
                  }
              }
              return null;
          }
  
          @Override
          protected void onProgressUpdate(String... values) {
              String str = values[0];
              text.setText(str);
          }
      }
  }
  </code></pre>