https://www.cwiki.us/display/android/Start+Another+Activity
现在,你需要对你的第二个 activity 进行修改,然后在这个 activity 中显示第一个 activity 输入的内容。
在 DisplayMessageActivity.java, 添加下面的代码到 onCreate() 方法中:
[code]@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);
}[/code]
单击 Alt + Enter (或者 Option + Enter 在 Mac 中)。你导入的类将会显示成下面的样子
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;