如何通过一个2渔政数组作为android的意图额外 [英] how to pass a 2 dimention array as an intent extra in android
问题描述
我通过二维数组[] []对象作为一个额外的意图到另一个活动,但其显示的错误我不能确定我该怎么办?
捆绑包= intent.getExtras();
SmsMessage []封邮件= NULL;
字符串str =;
如果(捆绑!= NULL)
{
// ---检索收到的短信---
[对象]的PDU =(对象[])bundle.get(的PDU);
封邮件=新SmsMessage [pdus.length]
的for(int i = 0; I< msgs.length;我++){
封邮件[I] = SmsMessage.createFromPdu((字节[])的PDU [I]);
STR + =短信来自+封邮件[I] .getOriginatingAddress();
STR + =;
STR + =封邮件[I] .getMessageBody()的toString()。
STR + =\\ n;的String [] [] xmlResponse2 = NULL;
的String [] =测试str.split(\\ n);
xmlResponse2 =新的String [0] [test.length];
的for(int i = 0; I< test.length;我++){
xmlResponse2 [0] [I] =试验[Ⅰ]; } 目的L =新意图(背景下,AgAppMenu.class);
l.putExtra(msg中,xmlResponse2 [0] [I]);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(升);
Intent.putExtra不接受2维数组按照下面的文档
http://developer.android.com/reference/android/content/Intent.html
我有检查Intent.putExtra源$ C $ C,它使用捆绑类用于存储数据。
http://developer.android.com/reference/android/os/ Bundle.html
下面是Intent.java来源$ C $ C
- Intent.java <一个href=\"http://gitorious.org/android-eeepc/base/blobs/fda6fae156e31a287e3cfbf66e51ea1405cdf479/core/java/android/content/Intent.java\" rel=\"nofollow\">http://gitorious.org/android-eeepc/base/blobs/fda6fae156e31a287e3cfbf66e51ea1405cdf479/core/java/android/content/Intent.java
- Bundle.java <一个href=\"https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/Bundle.java\" rel=\"nofollow\">https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/Bundle.java
Bundle.java使用的HashMap存储的内容,
我所知,它直接是不可能的。
您可以使用putParcelable方法,你需要创建自己的类的instanceof 2维数组。
一个快速的解决方案。
的String []键= createKeys();
的String []值= createValues();(keys.length == values.length)bundle.putExtra(钥匙,键);
bundle.putExtra(价值,价值);
I pass 2d array [][] object as an intent extra to another activity, but its show error i can not be identifies what do i do?
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
String[][] xmlResponse2= null;
String[] test = str.split("\n");
xmlResponse2= new String[0][test.length];
for (int i = 0; i < test.length; i++) {
xmlResponse2[0][i]=test[i];
}
Intent l = new Intent(context,AgAppMenu.class);
l.putExtra("msg",xmlResponse2[0][i]);
l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(l);
Intent.putExtra does not accept 2 dimension array as per the following document http://developer.android.com/reference/android/content/Intent.html
I have check the source code of Intent.putExtra , It use Bundle Class to store data
http://developer.android.com/reference/android/os/Bundle.html
Here is Source code of Intent.java
- Intent.java http://gitorious.org/android-eeepc/base/blobs/fda6fae156e31a287e3cfbf66e51ea1405cdf479/core/java/android/content/Intent.java
- Bundle.java https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/Bundle.java
Bundle.java use "HashMap" to store the content,
Best of my knowledge it's not possible directly
you can use putParcelable method, you need to create your own class instanceof 2 dimension array.
one quick solution
String[] keys = createKeys();
String[] values = createValues();
(keys.length == values.length)
bundle.putExtra("keys", keys);
bundle.putExtra("values", values);
这篇关于如何通过一个2渔政数组作为android的意图额外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!