title: How can I connect the main activity to another activity using a button?
body: <p>I'm new to Android and I have encountered a problem.
  The Gradle build is running fine and it has launched the application
  but whenever I click the button it does not navigate me to another screen.
  Here is the code:</p>
  <p><strong>mainactivity</strong></p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  public static final String EXTRA_MESSAGE = &quot;com.example.learn1.MESSAGE&quot;;
  EditText editText1;
  Button button;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  public void sendMessage(View view) {
      Intent intent = new Intent(this, Displaymsgactivity.class);
      EditText editText = (EditText) findViewById(R.id.editText1);
      Button btn = (Button)findViewById(R.id.open_activity_button);
      btn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              String message = editText.getText().toString();
              intent.putExtra(EXTRA_MESSAGE, message);
              startActivity(intent);
          }
      });
  
  }
  }`
  </code></pre>
  <p><strong>another activity Displaymsgactivity</strong></p>
  <pre><code>public class Displaymsgactivity extends AppCompatActivity {
  TextView textView;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_displaymsgactivity);
  
      Intent intent = getIntent();
      String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
  
      // Capture the layout's TextView and set the string as its text
      TextView textView = findViewById(R.id.textView);
      textView.setText(message);
  }
  }
  </code></pre>
  <p><strong>ActivityManifest.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  package=&quot;com.example.learn1&quot; &gt;
  
  &lt;application
      android:allowBackup=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/Theme.Learn1&quot;&gt;
      &lt;activity android:name=&quot;.MainActivity&quot;
          android:exported=&quot;true&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=&quot;.Displaymsgactivity&quot;
          android:parentActivityName=&quot;.MainActivity&quot;&gt;
          &lt;!-- The meta-data tag is required if you support API level 15 and lower --&gt;
          &lt;meta-data
              android:name=&quot;android.support.PARENT_ACTIVITY&quot;
              android:value=&quot;.MainActivity&quot; /&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>