package com.pingyijinren.test; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class IndexActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_index); Intent intent=new Intent(this,TransferObjectActivity.class); Person person=new Person(); person.setAge(26); person.setName("张钦雄"); intent.putExtra("person",person); startActivity(intent); } }
package com.pingyijinren.test; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class TransferObjectActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_transfer_object); Person person=(Person)getIntent().getSerializableExtra("person"); Log.d("MainActivity",person.getName()+" "+person.getAge()); } }
package com.pingyijinren.test; import java.io.Serializable; /** * Created by Administrator on 2016/5/20 0020. */ public class Person implements Serializable{ private String name; private int age; public void setName(String name){ this.name=name; } public void setAge(int age){ this.age=age; } public String getName(){ return name; } public int getAge(){ return age; } }