Can anyone tell me where to instantiate a singleton class object like ArrayList?
I am trying to instantiate in the onCreate()
method
but its not instantiated. Can any one tell me where to allocate it?
public class SharedVariables extends Application
{
public static ArrayList<ArrayList<Map<String,String>>> ArrayOfImageUrlDicts;
public static ArrayList<ArrayList<Map<String,String>>> ArrayOfImageNameDicts;
@Override
public void onCreate()
{
super.onCreate();
ArrayOfImageUrlDicts = new ArrayList<ArrayList<Map<String,String>>>();
ArrayOfImageNameDicts = new ArrayList<ArrayList<Map<String,String>>>();
}
}
This is actually not a real Singelton (see Wikipedia for an accurate Description of Singeltons) but a normal static variable. If you want to usemore static variables you may consider using this as it makes things much more beautiful. However to answer your concrete question you can either use a static block where you initialize those variables or initialize them directly after decleration.
or