Chr*_*ers 8 android multidimensional-array parcelable
我如何将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");
Run Code Online (Sandbox Code Playgroud)
Chi*_*rag 12
你可以使用putSerializable.数组是可序列化的.
储藏:
bundle.putSerializable("list", selected_list);
//这里bundle是Bundle对象.
要访问:
String[][] passedString_list = (String[][]) bundle.getSerializable("list");
Run Code Online (Sandbox Code Playgroud)
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putSerializable("list", selected_list);
mIntent.putExtras(mBundle);
Run Code Online (Sandbox Code Playgroud)
小智 6
这最终对我很有用:
要开始一个新活动(发送String [] []和String):
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);
Run Code Online (Sandbox Code Playgroud)
要在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];
}
}
Run Code Online (Sandbox Code Playgroud)
您可以定义一个自定义类,该类实现Parcelable
并包含从 Parcel 读取二维数组或向 Parcel 写入二维数组的逻辑。然后,将可打包的物体放入其中Bundle
进行运输。