I have this method which is used to store a list of Applications.
public void storeApplication(String name, String item){
peopleAttending.add(new Application(name, item));
}
It does what it's supposed to do, however when the method finishes, the data contained within the ArrayList also gets destroyed.
I've declared and instantiated the ArrayList globally:
private ArrayList<Application> peopleAttending = new ArrayList<>();
So I would have thought that once the object is added to the ArrayList, it would be safely stored until the program terminates.
Any help would be greatly appreciated.
Class that calls storeApplication:
public void saveBookingInfo(View view) {
GuestsAttending sendApplication = new GuestsAttending();
EditText applicantNameText = (EditText) findViewById(R.id.applicantNameTextField);
EditText itemToBurnText = (EditText) findViewById(R.id.itemToBurnTextField);
String appName = applicantNameText.getText().toString();
String appItemToBurn = itemToBurnText.getText().toString();
if (appItemToBurn.isEmpty() || appName.isEmpty()) {
Toast.makeText(BookingScreen.this, "Please fill in all fields.", Toast.LENGTH_SHORT).show();
}
else {
sendApplication.storeApplication(appName, appItemToBurn);
}
}
Edit - Entire class:
public class GuestsAttending extends Activity {
private ArrayList<Application> peopleAttending = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guests_attending);
}
public void storeApplication(String name, String item){
peopleAttending.add(new Application(name, item));
}
}