I know that we can able to pass the any object with its value to another activity with the method putExtra()
and getExtra
methods.
but now I want to know whether is it possible to pass the array to the another Activity
or not?
Or if it is then let me know how I can pass the array to the another Activity
?
Thanks.
Asked
Active
Viewed 3.0k times
11

DonGru
- 13,532
- 8
- 45
- 55

Shreyash Mahajan
- 23,386
- 35
- 116
- 188
5 Answers
32
Bundle b = new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);
And for receiveing
Bundle b = this.getIntent().getExtras();
String[] array=b.getStringArray(key);
-
ok Nice. But what if i want to pass the Array without value. I mean if i have already store the value in to the array and now if i want to pass it to another activiy by just name of the array then ? – Shreyash Mahajan Aug 31 '11 at 16:14
-
Have a look at this page http://androidhub.wordpress.com/2011/08/03/android-intents-for-passing-data-between-activities-part-2 – SSS Sep 14 '12 at 12:13
4
The Bundle
class has many putXxxxArray() methods.
- putBooleanArray
- putByteArray
- putCharArray
- putCharSequenceArray
- putDoubleArray
- putFloatArray
- putIntArray
- putLongArray
- putParcelableArray
- putShortArray
- putStringArray
If you are looking to pass some sort of Object
, you should look at the Parcelable
interface, as your Objects will need to implement it.

nicholas.hauschild
- 42,483
- 9
- 127
- 120
2
Firstly, you should know two issues:
- in order to send sth via an intent it must be parcelable
- even if an object is pacelable, there is limitation to the amount of data you can send via an intent.
A possible approach could be to have a static structure where you could store your data and pass with the intent only an index to that data. Using this index the new activity could get access to those data. Hope this helps.

Dimitris Makris
- 5,183
- 2
- 34
- 54
2
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putSerializable("bundle",Parceble Object);
intent.putExtra(String key, String[] values);
intent.putExtras(bundle);
And for different types of array look here.
Thnx

user370305
- 108,599
- 23
- 164
- 151
-
ok. Should i also have to send the value with the array ? It only name can make to fetch data ? – Shreyash Mahajan Aug 31 '11 at 16:21
-
here, there are static value you are given to the array during passing it. But in my case, i don't know how many values are there in the array. Means it can be changed based on the activity call. So how to define the range and values of that array ??? – Shreyash Mahajan Sep 01 '11 at 04:15
-
1if you don'tknow the size of array at runtime then you can use ArrayList
like, public void putStringArrayList (String key, ArrayList – user370305 Sep 01 '11 at 06:15value) -
So will i pass that array lise from one activity to another ? – Shreyash Mahajan Sep 01 '11 at 06:22
-
instead of that if i create bean class and use the getter setter methods for that then is it a good idea ???? – Shreyash Mahajan Sep 01 '11 at 06:23
-
yes, you will pass arraylist from one activity to other activity. And if you want to pass the other data different type of data then you can pass it in object, but if you want to pass only a single array then putStringArrayList (String key, ArrayList
value) is better. :-) – user370305 Sep 01 '11 at 06:26