On Sun, Dec 23, 2012 at 10:43 PM, Lew <[email protected]> wrote:

>
> Instances do not initialize static members in Java. The static members are
> initialized as part of
> class initialization.
>
> Instances can set static values if they're mutable, but that's not
> initialization.
>
> I don't know about processes being destroyed or not, but the creation or
> collection of instances in
> a JVM is not related to the initialization or destruction of static
> members.
>
> If the class is not unloaded, its static variables will continue to hold
> whatever values they had at the
> point of latest assignment, or their initialized values if there hasn't
> been an assignment.
>
> If a class is unloaded and reloaded, or loaded under a different
> classloader for the first time, it will be
> (re-)initialized upon the first subsequent class-initialization event
> (such as a reference to a member or
> creation of an instance).
>
> So your question reduces to finding out under what circumstances the class
> under investigation
> is unloaded, loaded and initialized.
>
> Based on the answers upthread, and I'm in no position to dispute them, the
> class does not unload
> every time the Activity stops. But it sometimes does.
>

I guess I was too terse.  Here's my reasoning in a bit more detail so it's
easier for you to understand.

If, by the time onCreate() starts executing, the static data already have
values that onCreate(), and no one else, writes to them, I'd say it means
onCreate() has executed already.  That would make the onCreate() call in
question the second one (at least) since the class was loaded.  The thing I
don't get is how would that be possible if Android doesn't collect
individual Activity instances, just whole processes.

What you write is basic Java and doesn't contribute to the explanation I'm
looking for.  If you can think of a mechanism for static data to survive
process termination and restart, that's what I'd like to hear.  I don't
know much about how Android works in this area.  Normally, I'd expect
process termination to mean JVM shutdown, with classes unloaded and
destruction of static data.  Could it be there's perhaps some advanced
caching going on allowing classes and statics to survive?

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