Display the message

Display the message


Now you will modify the second activity to display the message that was passed by the first activity.
  1. In DisplayMessageActivity.java, add the following code to the onCreate() method:
    @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();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
    
        // Capture the layout's TextView and set the string as its text
        TextView textView = (TextView) findViewById(R.id.textView);
        textView.setText(message);
    }
  2. Press Alt + Enter (or Option + Return on Mac) to import missing classes. Your imports should end up as the following:
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.ViewGroup;
    import android.widget.TextView;

Comments

Popular posts from this blog

Make the text box size flexible

Change the UI strings

Add Text box & Button