如何将2分母数组对象作为参数传递给另一个活动
如何在另一个活动中获取二维数组字符串值
String [][]str;
Intent l = new Intent(context,AgAppMenu.class);
l.putExtra("msg",str);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(l);
another Activity class
String[][] xmlRespone2;
xmlRespone2 = getIntent().getExtras().getString("msg");
发布于 2012-08-31 12:00:06
您可以使用可序列化的putSerializable.数组。
要存储:
bundle.putSerializable("list", selected_list);
//这里的捆绑包是捆绑对象。
要访问:
String[][] passedString_list = (String[][]) bundle.getSerializable("list");
示例
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putSerializable("list", selected_list);
mIntent.putExtras(mBundle);
发布于 2013-09-28 13:39:00
这对我来说终于行得通了:
要启动新活动(发送字符串和字符串):
String[][] arrayToSend=new String[3][30];
String stringToSend="Hello";
Intent i = new Intent(this, NewActivity.class);
i.putExtra("key_string",stringToSend);
Bundle mBundle = new Bundle();
mBundle.putSerializable("key_array_array", arrayToSend);
i.putExtras(mBundle);
startActivity(i);
要在NewActivity.onCreate中访问:
String sReceived=getIntent().getExtras().getString("key_string");
String[][] arrayReceived=null;
Object[] objectArray = (Object[]) getIntent().getExtras().getSerializable("key_array_array");
if(objectArray!=null){
arrayReceived = new String[objectArray.length][];
for(int i=0;i<objectArray.length;i++){
arrayReceived[i]=(String[]) objectArray[i];
}
}
发布于 2012-08-31 11:58:06
您可以定义一个自定义类来实现Parcelable
,并包含从/向Parcel读取和写入二维数组的逻辑。然后,将该可打包对象放入Bundle
中以进行传输。
https://stackoverflow.com/questions/12214847
复制