Java代码
public class Home extends Activity { public static final String ARRAYS_COUNT = "com.yourname.ARRAYS_COUNT"; public static final String ARRAY_INDEX = "com.yourname.ARRAY_INDEX"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final String data[][] = new String[][] {{"1","pavan"},{"2","kumar"},{"3","kora"},{"1","pavan"},{"2","kumar"},{"3","kora333"}}; Bundle bundle = new Bundle(); int count = data.length; bundle.putInt(ARRAYS_COUNT, ARRAY_INDEX ); for (int i = 0; i < count; i++) bundle.putStringArray(ARRAY_INDEX + i, data[i]); Intent intent = new Intent(this, Second.class); intent.putExtras(bundle); startActivity(intent); } } public class Second extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = getIntent().getExtras(); if (bundle != null) { int count = bundle.getInt(Home.ARRAYS_COUNT, 0); ArrayList<String[]> arrays = new ArrayList<String[]>(count); for (int i = 0; i < count; i++) arrays.add(bundle.getStringArray(Home.ARRAY_INDEX + i)); String[][] data = arrays.toArray(new String[][]{}); } } } Bundle b=new Bundle(); b.putStringArray(key, new String[]{value1, value2}); Intent i=new Intent(context, Class); i.putExtras(b);
方式有很多,如果你不想new Bundle来传
调用intent的intent.putExtra(name, value)两次就可以了
String[] str1 = {"aa","aa"}; String[] str2 = {"bb","bb"}; Intent intent = new Intent(); intent.putExtra("dev1", str1); intent.putExtra("dev2", str2); intent.setClass(this, OtherActivity.class); startActivity(intent);
在取数据的OtherActivity中
String[] dev = this.getIntent().getStringArrayExtra("dev1"); String[] div = this.getIntent().getStringArrayExtra("dev2");
就拿到了字符串