Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im new to android.

how to get the array values from one class to another class using Intent??

I tried like this... 1st activity...

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

2nd activity

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

Im getting this as warning and im getting null as the value in 2nd second activity..

     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)
share|improve this question

2 Answers

up vote 0 down vote accepted

use a Bundle:

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

than in Videoplayer Activity:

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

Edit: in the question is a bit unclair if resim_list in a String[] or an ArrayList. If resim_list is an ArrayList

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

to store it and

 bundle.getStringArrayList("string-array")

to retrieve it

share|improve this answer
with startActivity. As usual. – blackbelt May 6 at 12:47
is resim_list a String array? – blackbelt May 6 at 13:04
ArrayList<String> – OneManArmy May 6 at 13:06
ok, then see my edit – blackbelt May 6 at 13:08
Thank a lot...it work for me.. – OneManArmy May 7 at 6:35

Maybe your resim_list instance is an ArrayList

You should store a String[] with :

videointent.putExtra("string-array", resim_list.toArray(new String[resim_list.size()]));
share|improve this answer
yes its ArrayList<String> – OneManArmy May 6 at 12:47
In 2nd activity how to get it??? – OneManArmy May 6 at 12:53
The same way you already did. – Orabîg May 6 at 12:54
While printing in logcat i get like this String Video[Ljava.lang.String;@40709f38 – OneManArmy May 6 at 13:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.