这是创建单例类的方法:
public class YourSingleton { private static YourSingleton mInstance; private ArrayList<String> list = null; public static YourSingleton getInstance() { if(mInstance == null) mInstance = new YourSingleton(); return mInstance; } private YourSingleton() { list = new ArrayList<String>(); } // retrieve array from anywhere public ArrayList<String> getArray() { return this.list; } //Add element to array public void addToArray(String value) { list.add(value); }}任何需要调用arrayList的地方都可以:
YourSingleton.getInstance().getArray();
要将元素添加到数组,请使用:
YourSingleton.getInstance().addToArray("first value");要么
YourSingleton.getInstance().getArray().add("any value");


