MainActivity.java
Button buttonShow; EditText editTextMessage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); buttonShow= (Button) findViewById(R.id.buttonShow); editTextMessage= (EditText) findViewById(R.id.editTextMessage); } protected void buttonShow_onClick(View view){ String message=editTextMessage.getText().toString(); Intent intent=new Intent(this,SecondActivity.class); intent.putExtra("msg",message); startActivity(intent); }
SecondActivity.java
TextView textViewMessage; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Intent intent=this.getIntent(); // Bundle bundle=intent.getExtras(); String message=intent.getStringExtra("msg"); textViewMessage= (TextView) findViewById(R.id.textViewMessage); textViewMessage.setText(message); }
References
https://github.com/mhdr/AndroidSamples/tree/master/001