I have a MyApplicationClass into which I stock An ArrayList, then I create a variable ArrayList in my MainActivity and assign it the variable in MyApplciationClass and finally I call remove to the local variable to remove a value but the value is removed from both MyApplicationClass and the localvariable and it can be possible because I just retrieve the list from MyApplicationClass I didin't make anything else ?
Here is my code:
MyApplicationClass:
private ArrayList<String> text = new ArrayList<>();
public ArrayList<String> getText() {
return text;
}
public void addTest(String input) {
text.add(input);
}
MainActivity:
//When click on a button:
final MyApplicationClass myApplicationClass = (MyApplicationClass) getApplicationContext();
//I add some example values
myApplicationClass.addTest("1");
myApplicationClass.addTest("2");
//Here I retrieve the variable in MyApplicationClass to put in into a local variable:
ArrayList<String> testlocal = myApplicationClass.getText();
//And here I remove a value from the localvariable testlocal:
test.remove(1);
But when I debug and see variable I can see that the value is correctly deleted in testlocal but too in text in MyApplicationClass but I just want to remove a value from textlocal.
Thanks a lot.