Peter Carpenter wrote:
> And this is where my question lies…   What happens to the static
> variables?

They are definitely gone when the process is terminated.

Things get a bit murky if all components are stopped, since outside
forces (e.g., broadcast intents) might trigger your code again, and it
might use the same process if that process is still hanging around.

This is one of the many reasons to avoid static variables wherever possible.

> Meaning that a restart of a service does not guarantee a new set
> of initialised static variables.

Correct.

> 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. L

Launch a string of expletives in the general direction of the original
author. Unless that author is you, of course. ;-)

> 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)

Better yet, get rid of the static variables.

> 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?

You can force-terminate your process via System.exit(). Some people have
had success with that technique. However, bear in mind this will kill
off anything that is running in your process, so unless you have
absolute control over when and how your components run, you might
clobber something trying to do some work.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, $35/Year

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to