I have an issue with singleton in an app created in android studio.
Class MyApplication is created :
public class MyApplication extends Application { // code - freeCodeCamp.org
private static MyApplication singleton;
private List<Location> myLocations;
public List<Location> getMyLocations() {
return myLocations;
}
public void setMyLocations(List<Location> myLocations) {
this.myLocations = myLocations;
}
public MyApplication getInstance(){
return singleton;
}
public void OnCreate() {
super.onCreate();
singleton = this;
myLocations = new ArrayList<>();
}
}
And when i call MyApplication in Main aactivity it gives an error , specific null:
MyApplication myApplication = (MyApplication)getApplicationContext();
savedLocations = myApplication.getMyLocations();
savedLocations.add(currentLocation);
currentLocation has a valid Location value. Any hints? thanks