intent传递数据方法总结

传递正常数据:
1:intent 传递:
Intent intent = new Intent(context, HomeDetailActivity.class);
intent.putExtra(“url”,newest.url);
Log.e(“jxf”,”home页列表点击位置url”+newest.url);
context.startActivity(intent);
getActivity().overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

获取:
Intent intent=getIntent();
url=intent.getStringExtra("url");

2:intent 封装bundle:bundle传递数据

Intent intent=new Intent(context, ChannelActivity2.class);
Bundle bundle = new Bundle();
bundle.putInt("teacherId", contents.get(position - 1).teacherId);
bundle.putString("portraitUrlSmall", contents.get(position - 1).portraitUrlSmall);
bundle.putString("portraitUrlBig", contents.get(position - 1).portraitUrlBig);
bundle.putString("nickname", contents.get(position - 1).nickname);
bundle.putString("catgoryName", contents.get(position - 1).catgoryName);
bundle.putString("catgoryId", contents.get(position-1).catgoryId);
bundle.putInt("catgoryIdMark", catgoryId);
intent.putExtras(bundle);
context.startActivity(intent);
getActivity().overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

获取:
Bundle bundle=getIntent().getExtras();
teacherId=bundle.getInt("teacherId");
portraitUrlSmall=bundle.getString("portraitUrlSmall");
portraitUrlBig=bundle.getString("portraitUrlBig");
nickname=bundle.getString("nickname");
catgoryNames=bundle.getString("catgoryName");
catgoryIds=bundle.getString("catgoryId");
catgoryIdMark= bundle.getInt("catgoryIdMark");

3:intent传递序列化对象集合
Intent intent=new Intent(SubscriptionActivity.this,PlayActivity.class);
intent.putExtra(“list”, (Serializable) lessons);

获取:
lessons= (ArrayList<MusicLesson>) getIntent().getSerializableExtra("list");

4:intent传递序列化对象集合和其他数据
Intent intent=new Intent(SubscriptionActivity.this,PlayActivity.class);
Bundle bundle=new Bundle();
bundle.putString(“portraitUrlSmall”, portraitUrlSmall);
bundle.putString(“nickname”, nickname);
bundle.putInt(“itemposition”, position);
intent.putExtras(bundle);
intent.putExtra(“list”, (Serializable) lessons);
startActivityForResult(intent, 500);
overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

获取:
Bundle bundle = getIntent().getExtras();
portraitUrlSmall=bundle.getString("portraitUrlSmall");
nickname=bundle.getString("nickname");
itemposition=bundle.getInt("itemposition");
lessons= (ArrayList<MusicLesson>) getIntent().getSerializableExtra("list");
title=lessons.get(itemposition).title;
categoryName=lessons.get(itemposition).categoryName;
pictureUrlSmall=lessons.get(itemposition).pictureUrlSmall;
url=lessons.get(itemposition).url;
initCurrentposition=lessons.get(itemposition).currentposition;

5:intent封装bundle传递序列化对象
Intent intent = new Intent(context, DetailofHistoryTicketActivity.class);
TicketInfoBean ticketInfoBean = ticketInfoBeans.get(position-1);
Log.e(“jxf”,”打印传递的字符串对象ordersTicketDetailProtocolList+++++++”+ticketInfoBean.ordersTicketDetailProtocolList);
Bundle bundle=new Bundle();
bundle.putSerializable(“ticketInfoBean”, ticketInfoBean);
intent.putExtras(bundle);
context.startActivity(intent);
getActivity().overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

获取:
TicketInfoBean ticketInfoBean= (TicketInfoBean) getIntent().getSerializableExtra("ticketInfoBean");


序列化的传递:值是传递对象的一份copy:并不是和上页传递过来的对象是同一对象:比如:改变对象,另一页的并不会发生改变。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值