如何传递的对象(任何对象)的列表,通过捆绑,从活动A到活动B? [英] How can i pass a list of objects (any object), through bundle, from activity A to Activity B?

查看:112
本文介绍了如何传递的对象(任何对象)的列表,通过捆绑,从活动A到活动B?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Android平台上,我有型(FitItem)的对象列表,我想从我的活动一通列表中另一个活动B,并在活动B我想再次获得对象的列表


解决方案

 意图yourIntent =新意图(activityA.this,activityB.class);
捆绑yourBundle =新包();
yourBundle.putString(名,值);
yourIntent.putExtras(yourBundle);
startActivity(yourIntent);

和你在接下来的活动值(在的onCreate()

 捆绑yourBundle = getIntent()getExtras()。
字符串s = yourBundle.getString(名称);

这个例子传递一个字符串,但你应该能够掌握如何使用它的其他对象。

This is on the android platform, i have a list of objects of type (FitItem), and i want pass the list from my activity A to another activity B, and on the activity B i want get the list of objects again

解决方案

Intent yourIntent = new Intent(activityA.this, activityB.class);
Bundle yourBundle = new Bundle();
yourBundle.putString("name", value);
yourIntent.putExtras(yourBundle);
startActivity(yourIntent);

And you get the value in the next Activity (in your onCreate()):

Bundle yourBundle = getIntent().getExtras();
String s = yourBundle.getString("name");

This example is passing a String, but you should be able to grasp how to use it for other objects.

这篇关于如何传递的对象(任何对象)的列表,通过捆绑,从活动A到活动B?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆