Passing an ArrayList or creating a new one?

74 Views Asked by At

I'm building an application in which I create the same ArrayList in every Activity. An other option is creating the ArrayList in the first Activity and then pass it on to other activities. However, I don't know if this is 'better' than creating the same ArrayList every time. I know by creating a new ArrayList it would take up a bit of memory (ArrayList is not so big), but passing an ArrayList by using an Intent slows your app down, right?

What's the best option to go with?

With kind regards, Koen

3

There are 3 best solutions below

0
profbreach On

Why don't you try to provide the Arraylist system wide?

For example this could be an option: Android global variable

0
Masoud Badrmiran On

You can simply make an ArrayList in custom Application class and use it in every Activity

0
Sadashiv Margi On

Arraylist in java are the reference variable so passing an arrayList is better approach than creating every time, unless you don't have any write operation on it, otherwise it will give you inconsistency result,