在Android开发中,有时候需要从一个Activity中传递数据到另外一个Activity中,通过Intent传递值,支持基本数据类型和String对象及它们的数组对象byte、byte[]、char、 char[]、boolean、boolean[]、short、short[]、int、int[]、long、long[]、float、 float[]、double、double[]、String、String[],还有实现Serializable、Parcelable接口的类对 象。
这些方法可以查看:
http://developer.android.com/reference/android/content/Intent.html#putStringArrayListExtra(java.lang.String, java.util.ArrayList) http://developer.android.com/reference/android/content/Intent.html#putStringArrayListExtra(java.lang.String, java.util.ArrayList)
public Intent putStringArrayListExtra (String name, ArrayList<String> value)
Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
Parameters
name | The name of the extra data, with package prefix. |
---|---|
value | The ArrayList data value. |
Returns
- Returns the same Intent object, for chaining multiple calls into a single statement.
用于传递对象
传递对象的案例:
package com.example.one;
import android.os.Parcel;
import android.os.Parcelable;
public class Person implements Parcelable{
private String name;
private int age;
private String sex;
private String address;
publ