I am writing a simple Android application, which is basically a modification of the fragment demo available in the Android documentation. The application has a file called Ipsum.java, which has a static ArrayList of strings called headers.
In the onCreate () method of the main action, I have the following code that adds some elements to the list of arrays.
if (savedInstanceState == null){ Ipsum.Headlines.add("String 1 "); Ipsum.Headlines.add("String 2"); }
savedInstanceState is the set that the system passes to the method if the application resumes from some inactive state. The logic is that if savedInstanceState is NULL, then the application does not resume, but starts as a new instance.
If I leave the application using the Home button and run the application again, the List array contains only two elements: "String 1" and "String 2". (This is the desired behavior)
However, if I leave the application using the back button, and then enter the application again, the elements "String 1" and "String 2" will be added again . Then the array has 4 elements.
String 1 String 2 String 1 String 2
(The contents of arrayList can be seen as they are used to populate the listView) It seems that the application stores the contents of the list of static arrays when the "Back" button is pressed .. and that the package is not passed to the onCreate () method when the application restarts. Can someone explain what is happening here in terms of the application life cycle?
source share