2013-05-06 160 views
0

Im新的android。键字符串数组预期的字符串[],但值是一个java.util.ArrayList

如何从一个类的数组值到另一个类使用Intent?

我想是这样的... 1日活动...

Intent videointent = new Intent(Focusarea.this,Videoplayer.class); 
videointent.putExtra("string-array", resim_list); 
startActivity(videointent); 

第二活性

 Intent intent=getIntent(); 
    String [] Array = intent.getStringArrayExtra("string-array"); 

即时得到此为警告,并即时得到空作为第二次活动的价值..

 W/Bundle(521): Key string-array expected String[] but value was a 
    java.util.ArrayList. The default value <null> was returned. 
    W/Bundle(521): Attempt to cast generated internal exception: 
    W/Bundle(521): java.lang.ClassCastException: java.util.ArrayList 
    W/Bundle(521):  at android.os.Bundle.getStringArray(Bundle.java:1459) 
    W/Bundle(521):  at 
    android.content.Intent.getStringArrayExtra(Intent.java:3630) 
     W/Bundle(521): at 
    com.example.TEENEINSTIEN.Videoplayer.onCreate(Videoplayer.java:20) 
     W/Bundle(521): at 
     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 

回答

1

使用Bundle

Bundle bundle = new Bundle(); 
bundle.putStringArray("string-array", resim_list); 
videointent.putExtras(bundle); 

Videoplayer活动:

Bundle bundle = getIntent().getExtras(); 
String [] myStringArray = bundle.getStringArray("string-array"); 

编辑:在问题有点unclair如果resim_listString[]ArrayList 。 如果resim_listArrayList

bundle.putStringArrayList("string-array", resim_list); 

来存储它和

bundle.getStringArrayList("string-array") 

找回它

+0

with startActivity。照常。 – Blackbelt 2013-05-06 12:47:43

+0

是resim_list的一个String数组吗? – Blackbelt 2013-05-06 13:04:37

+0

ArrayList 2013-05-06 13:06:42

0

也许你resim_list实例是一个ArrayList

,可以储存一个String []与:

videointent.putExtra("string-array", resim_list.toArray(new String[resim_list.size()])); 
+0

是它的ArrayList 2013-05-06 12:47:45

+0

第二次活动如何得到它? – 2013-05-06 12:53:36

+0

就像你已经做过的一样。 – 2013-05-06 12:54:06

相关问题