for some time, I was blissfully aware that static variables [instance] exist while the application was running. however, to my horror and dismay, I feel that this is not true.
for simple testing, I created a static list of strings, and in my main class activity override the onDestroy method to print a message to verify that the application exited. in the onCreate method onCreate I just added a new string and printed the contents of the list. I found that the size of the list continues to increase, and all the previously added row values ββare still present.
I read in places [even here on SO] that instance variables exist as long as the application is running, but I'm afraid it is not.
To be more precise, I found out about this issue when using the Android SDK for Android. I saw that the AuthListener instances in the list of listeners in the SessionEvents class simply continue to grow over time. Therefore, whenever the application starts and the user logs in using FB, the listener methods are run as many times as there are instances present in the SessionEvents class.
Someone has watched this before, and is there some kind of fundamental error that I make in understanding how the android works?
what gives?
thank you for reading!
[ UPDATE ]
I am fixing BalusC and rdineiu . I really did not want to create confusion here about instance and class variables. Alas, in my haste to publish my question, I made a mistake that I did not want. I know very well the difference between static and instance variables. I just intended to write class variables and can't figure out what happened to refer to static variables as instance variables.
However, my question is still standing. @MisterSquonk - no, I'm not confused here when my activity ends and when the application is destroyed. Here is what I tried on the sample - I have only ONE activity that serves as Main . When I click the back button from this activity , I assume that the activity is removed from the stack and the application is also destroyed. I started the task manager to verify that my application is no longer working.
source share