title: How to restore the previously entered text in edittext in mainActivity on returning to it from another activity?
body: <p>I have a basic application with 2 activities as shown in the image:
  <a href="https://i.stack.imgur.com/Lc2Kh.png" rel="nofollow noreferrer">The left screen is mainActivity, right screen is secondActivity</a></p>
  <p>If the user presses the ​ Back button on the second activity, the application will go back to
  the first activity. I want that the text the user has entered in the first
  activity (either through voice input or directly as text) is displayed again in the editable
  text field.</p>
  <p>Here is my code for the mainActivity():</p>
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  }
  
  /** Called when the user taps the Send button */
  public void sendMessage(View view) {
      Intent intent = new Intent(this, DisplayMessageActivity.class);
      EditText editText = (EditText) findViewById(R.id.textMessage);
      String message = editText.getText().toString();
      intent.putExtra(EXTRA_MESSAGE, message);
      startActivity(intent);
  }
  </code></pre>
  <p>I tried including finish() in my second activity as follows but this doesn't work:</p>
  <pre><code>String message;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_display_message);
  
      // Get the Intent that started this activity and extract the string
      Intent intent = getIntent();
      message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
  
  
  
  }
  @Override
  public void onBackPressed() {
  
          finish();
  }
  </code></pre>
  <p>I read that if I don't finish my mainActivity on transitioning to the 2nd activity, it will be restored on returning to it but I do not call finish() anywhere in my mainActivity.</p>
  <p>What is the most efficient way to do this?</p>
  <p>Edit:
  I found the fix. The text was restored on clicking the system back button already. It was not being restored on clicking the back button on the top bar which was resolved by adding the launchMode tag to the mainactivity section in the manifest file as follows:</p>
  <pre><code>&lt;activity android:name=&quot;.MainActivity&quot; android:theme=&quot;@style/Theme.AppCompat.NoActionBar&quot; android:launchMode= &quot;singleTop&quot;&gt;
  </code></pre>