如何发送的ArrayList<对象>从一个活动到第二项活动? [英] How to send ArrayList<object> from one activity to second activity?

查看:118
本文介绍了如何发送的ArrayList<对象>从一个活动到第二项活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个活动到次活动通过的ArrayList objArrayList,并希望得到那里。我创建一个简单的类中有四个数组列表。我米创建该类的对象,并通过传递数组列表中添加参数调用这个类的方法。之后,余米将在objArrayList该类对象。   如何传递objArrayList从一个活动到第二个活动,并接受它呢?

I want to pass "ArrayList objArrayList" from one activity to second activity and want to receive there. I am creating a simple class in that there are four arraylist. I m creating object of that class and calling method of that class by passing parameters to be added in arraylist. After that I m adding that class object in objArrayList. HOw can I pass objArrayList from one activity to second activity and receive it there?

谢谢, Vishakha。

Thanks, Vishakha.

推荐答案

第一上下文(可以是活动/服务等)

您有几种选择:

1)使用包从的的 http://developer.android.com/reference/android/content/Intent.html相对=nofollow>意图

1) Use the Bundle from the Intent:

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);  

2)创建一个新的捆绑

2) Create a new Bundle

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);

3)使用<一个href="http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20java.lang.String%5b%5d%29"相对=nofollow> putExtra()的意向快捷方式

Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);

新上下文(可以是活动/服务等)

Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
     String value = myIntent.getExtras().getString(key);
}

注意:捆绑有得与放的方法对所有的基本类型,parcelables的,和Serializables。我只是用字符串示范的目的。

NOTE: Bundles have "get" and "put" methods for all the primitive types, Parcelables, and Serializables. I just used Strings for demonstrational purposes.

您ArrayList类必须是Parcelable或序列化。所以,你应该继承它,因为我认为他们从原来的执行错过添加这些功能。

Your Arraylist class must be Parcelable or Serializable. So you should subclass it to add these functionalities as I think they miss from the original implementation.

再看看这些问题,他们会帮助你。 <一href="http://stackoverflow.com/questions/3136922/serialization-issue-with-sortedset-arrays-an-serializable">Serialization问题的SortedSet,数组的序列化

Then look into these other questions they will help you. Serialization issue with SortedSet, Arrays, an Serializable

这篇关于如何发送的ArrayList&LT;对象&gt;从一个活动到第二项活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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