传递正常数据:
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:并不是和上页传递过来的对象是同一对象:比如:改变对象,另一页的并不会发生改变。