1

How i can access ArrayList from one Activity to another and also clear ArrayList value?

djot
  • 2,952
  • 4
  • 19
  • 28
Selva
  • 839
  • 10
  • 25
  • 40
  • 1
    [My answer here](http://stackoverflow.com/questions/8573796/keeping-a-variable-value-across-all-android-activities/8573991#8573991) – st0le Jan 28 '12 at 08:19

2 Answers2

2

you can use setter/getter method for it.

public class MySetGet
{
    private ArrayList aList = null;

    public void setList ( ArrayList aList )
    {
            this.aList = a.List;
    }

    public ArrayList getList () 
    {
        return aList;
    }
}

Now you can set its value from any Activity/Class and get its value from any Activity/Class.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
1

The most simply and possible way to do the desired::

1.Create a simple public class say Data.. Now create a public static your Array list object.

Now access any where..

Data.listObj

2.Create the List object as public static in one activity and use in another via,

SecondActivity.listObj.clear();
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Arpit Garg
  • 8,476
  • 6
  • 34
  • 59