String data = "Hello";
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
intent.putExtra("data",data);
startActivity(intent);
String data = getIntent().getStringExtra("data");
Toast.makeText(this, ""+data, Toast.LENGTH_SHORT).show();
如果用intent传递对象
就把对应的Bean类implements Serializable
Person person = new Person();
.....
intent.putExtra("person",person);
Person person = (Person) getIntent().getSerializableExtra("person");
还有一种Parcelable方法,比较复杂,但效率高
网友评论