First of all i wanna say that how to pass Arraylist between activities. I wanna know whether whole arraylist is passed on using intent or just its base adress is transferred. (as in C) Moreover if whole arraylist is passed then is there any mechanism to just transfer its base as in c so multiple activities can use a single arraylist n not copy of same arraylist. Note Before downvoating this question i qanna say that i had visited many ither arraylist related questions on stackoverflow but none had explained my problem.
Asked
Active
Viewed 41 times
-4
-
Can u send me few references – Shivendra Saxena Jan 12 '18 at 15:43
-
sure google.com + android source Bundle – Selvin Jan 12 '18 at 15:43
-
Why don't you create a sample and debug . Check it yourself .I think this is the best way to find out . – ADM Jan 12 '18 at 15:45
-
Definitely i had done that and i think that whole arraylist is passed but i am not sure about this and only to confirm it i had posted this question – Shivendra Saxena Jan 12 '18 at 15:48
2 Answers
0
ArrayList<String> arr = new ArrayList<>();
arr.add("Hello");
Intent intent = new Intent(MainActivity.this, ToActivity.class);
intent.putExtra("array_list", arr);
startActivity(intent);
In ToActivity activity:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
ArrayList<String> arr = b.getStringArrayList("array_list");
}

Rajan Singh
- 309
- 2
- 7
0
Data that can be passed through intents are Serializable, Parcelable or primitive type. ArrayList is already serializable so it gets serialized when passed across activities. If you want to use same Arraylist in different activities you can create singleton to access the same ArrayList from different points

mguest
- 121
- 2
-
I had learnt that singletons aren't performance efficient is there any better alternative – Shivendra Saxena Jan 13 '18 at 11:12