Intent传递数据(项目中经常用到的几种类型)

1、传递ArrayList数据

ArrayList

Intent list_intent = new Intent();

list_intent.putStringArrayListExtra(“key值”, m_list);

list_intent.setClass(MainActivity.this, ListActivity.class);

startActivity(list_intent);

接收

arrayList = getIntent.getExtras().getStringArrayList(“keyzhi”);

ArrayList Object序列化

ArrayList object = new ArrayList();//object类必须implement Serializable

Intent intent = new Intent(A.this, B.class);

Bundle args = new Bundle();

args.putSerializable("obecjtList",(Serializable)object);

intent.putExtra("bundle",args);

startActivity(intent);

2.接受

Intent intent = getIntent();

Bundle args = intent.getBundleExtra("bundle");

ArrayList object = (ArrayList) args.getSerializable("obecjtList");

2、传递javabean

首先先要把Bean序列化

Intent intent =new Intent();

intent.putExtra("key值",bean);

intent.setClass(activity, SecondActivity.class);

startActivity(intent);

接收

bean= (Bean) getIntent().getSerializableExtra("key值");

3、传递普通数据

Intent intent =new Intent();

intent.putExtra("key值",“字符等等”);

intent.setClass(activity, SecondActivity.class);

startActivity(intent);

接收

String str =getIntent().getStringExtra("key值");

你可能感兴趣的:(Intent传递数据(项目中经常用到的几种类型))