wk843620202的专栏

如何使用Intent传递对象

我们可以使用

Intent intent = new Intent(this, SecondActivyt.class);intent.putExtra("isBoy", true);intent.putExtra("age", 24);intent.putExtra("name", "jane");

如果我们想用Intent传递对象,那么这个

public class Person implements Serializable {private String name;private String password;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Person() {super();}public Person(String name, String password) {super();this.name = name;this.password = password;}}

这里因为Person实现了Serialable

Person person = new Person("wk","123");Intent intent = new Intent(this, SecondActivyt.class);intent.putExtra("person_data", person);startActivity(intent);

在SecondActivity

Person person = (Person) getIntent().getSerializableExtra("person_data");

,想像力比知识更重要

wk843620202的专栏

相关文章:

你感兴趣的文章:

标签云: