Intent使用Serializable以及Parcelable傳遞數據

使用Serializable

Serializable是序列化的意思,表示將一個對象轉換成可存儲或可傳輸狀態,序列化的對象可以在網上傳輸也可以存儲到本地。序列化的方法只需要寫一個類繼承Serializable就可以了。如下:

public class Person implements Serializable{
    private String name;
    private int age;

    public String getName(){
        return name;
    }

    public int getAge(){
        return age;
    }

    public void setName(String name){
        this.name = name;
    }

    public void setAge(int age){
        this.age = age;
    }
}

然後接下去的操作就是我們所熟悉的了

Person person=new Person();
Intent i=new Intent(this,SecondActivity.class);
i.putExtra("data_person",person);

未完待更新…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章