Display the message
Display the message
Now you will modify the second activity to display the message that was passed by the first activity.
- In
DisplayMessageActivity.java
, add the following code to theonCreate()
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); }
- 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
Post a Comment