title: EditText.getText() returns text from different view in onPause after rotating device
body: <p>I have a strange problem here with an EditText view. In onPause() after an orientation change, the EditText view returns text via getText() that was never assigned to it. </p>
  
  <p>In fact, the EditText object in question is only assigned an empty string.
  In the error situation, it returns part(!) of a text that was assigned to a <em>different</em> TextView.</p>
  
  <p>This does however <em>not</em> happen if onPause is triggered by pressing the "back" key.</p>
  
  <p>Can anybody give me a clue? I do not understand what is happening here:</p>
  
  <p>My activity:</p>
  
  <pre><code>package com.example.rotationtest;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.content.DialogInterface;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      private final String LOG_TAG = "Test";
      private EditText mEditText;
      private TextView mTextView;
      private EditOk mEditOk;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mTextView = (TextView) findViewById(R.id.title);
          mEditText = (EditText) findViewById(R.id.editText);
          mEditText.setText("");
  
          mEditOk = new EditOk() {
  
              @Override
              public void ok(String result) {
                  mTextView.setText(result);
              }
          };
  
          editTextDialog(R.string.dialog_title, (CharSequence)getString(R.string.dialog_title), mTextView.getText().toString(), mEditOk);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return true;
      }
  
      abstract class EditOk {
          abstract public void ok(String result);
      }
  
      void editTextDialog(int titleId, CharSequence message, String text,
              final EditOk ok) {
          LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
          View layout = inflater.inflate(R.layout.edittext_dialog,
                                         (ViewGroup) findViewById(R.id.layout_root));
  
          TextView messageView = (TextView) layout.findViewById(R.id.text);
          messageView.setText(message);
          final EditText input = (EditText) layout.findViewById(R.id.editTextDialog);
          Log.d(LOG_TAG, "input = " + input);
          input.setTransformationMethod(android.text.method.SingleLineTransformationMethod.getInstance());
          input.setText(text);
          new AlertDialog.Builder(this)
              .setTitle(titleId)
              .setView(layout)
              .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int which) {
                              String newName = input.getText().toString();
                              if (newName.length() != 0) {
                                  ok.ok(newName);
                              }
                          }})
              .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      setResult(RESULT_CANCELED);
                      finish();
                  }
              })
              .create().show();
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          Log.d(LOG_TAG, "onPause: editText is " + mEditText.getText());
      }
  }
  </code></pre>
  
  <p>and layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;TextView
          android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="false"
          android:text="@string/hello_world"
          tools:context=".MainActivity" /&gt;
  
      &lt;EditText
          android:id="@+id/editText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@id/title"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="22dp"
          android:ems="10"
          android:inputType="textMultiLine" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>There is an AlertDialog involved which's layout is this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/layout_root" android:orientation="vertical"
      android:layout_width="fill_parent" android:layout_height="fill_parent"
      android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingBottom="20dp" android:paddingTop="15dp" android:layout_gravity="top"&gt;
      &lt;TextView android:id="@+id/text" android:layout_width="wrap_content"
          android:layout_height="wrap_content" android:textColor="#FFF"
          android:gravity="top" android:textSize="16sp" android:paddingBottom="20dp"/&gt;
  
      &lt;EditText
          android:id="@+id/editTextDialog"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;requestFocus&gt;&lt;/requestFocus&gt;
      &lt;/EditText&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Now the steps are these:</p>
  
  <ul>
  <li>Start activity in portrait orientation. A dialog pops up containing an EditText, prefilled with "Hello World!"</li>
  <li>Append "zzz" to "Hello world!"</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/gauUj.png" alt="enter image description here"></p>
  
  <ul>
  <li>Press OK. "Hello world!zzz" is now assigned to the TextView on the Activity.</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/jpnXo.png" alt="enter image description here"></p>
  
  <ul>
  <li>Now rotate the device to landscape. In onPause, mEditText.getText() now returns "zzz" although mEditText was not touched at all.</li>
  </ul>
  
  <p>Any ideas? My expectation is that mEditText.getText() always returns "". If you repeat these steps but trigger onPause() by pressing back instead of rotating the device, getText() indeed does return "" as expected. Why not when rotating the device?</p>
  
  <p>Additional note: I noticed that the soft keyboard seems to be necessary for the issue to appear. On an emulator with "Keyboard support = yes", the issue doesn't show up.</p>