Hi all,
We are currently porting some java code to work inside a service within the Android framework. However one thing I am still puzzling over is the life cycle of an android application, activity, & service. What I am currently thinking is this: 1. An android "application" process is created (The equivalent of starting a jvm) 2. An activitiy is loaded which will cause required classes to be loaded, static initialisers run, and the same for all referenced classes as the activity runs. 3. The activity launches a service (more classes loaded & static initialisers run) 4. The service stops. 5. The activity launches the service again. (static variables remain as last left) 6. The service stops. 7. The activity stops (static variables still remain as last left) 8. ... 9. ... 10. The activity starts (static variables still remain as last left) 11. the activity stops 12. ... 13. ... 14. The application is removed from memory by Anrdoid (only now are static variables killed) And this is where my question lies... What happens to the static variables? I would assume that because they are in the same "jvm" effectively as the activity, that they continue to contain their original values. Furthermore, I am assuming that even if the the server or activity is stopped - their respective classes with their static variables will stay around in memory until Android decides to remove them. Meaning that a restart of a service does not guarantee a new set of initialised static variables. Unfortunately the code I'm porting includes lots of static references that assumes an initial clean state and leaves the JVM to clear everything as it's stopped and started. :-( So is my thinking on the lifecycle correct? If so what would be the way forward? Am I forced to pore over this code with a fine tooth comb and ensure that the static variables are initialised correctly (LOTS of work), or is there some kind of (dirty) shortcut that I can use that will allow me to effectively unload the application (on activity exit?) forcing the 'jvm' to reinitialise the static variables on next activity startup? Cheers, Peter. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

