虽然知识非常基础,但我觉得无论是否是难点,即便非常简单的知识,及时写出来对知识积累都是有好处的。今天写一下Intent的数据传递。

发送端:

//创建Intent
Intent intent = new Intent();

//把需要传递的内容放进Intent
intent.putExtra("id", waitInfo.id);
intent.putExtra("warnning_star", warnning_star);
intent.putExtra("fengxlx", waitInfo.fengxlx);
intent.putExtra("chehao", waitInfo.chehao);
intent.putExtra("content", waitInfo.content);
intent.putExtra("time", waitInfo.time);

//设置即将要启动的Activity
intent.setClass(getActivity(), ZaiTuYuJing_FengXCL_XiangXXX_Activity.class);

//跳转
startActivity(intent);

接收端:

//接收Intent
Intent intent = getIntent();

//取出捆绑数据
Bundle bundle = intent.getExtras();

//从数据中根据key取出所需内容
int index = Integer.parseInt(bundle.getString("id"));
String chehao = bundle.getString("chehao");
String content = bundle.getString("content");
String time = bundle.getString("time");