android - What exactly does onDestroy() destroy? -
i've been bothered "characteristics": when use button leave app, can tell ondestroy() called, next time run app, static members of activity class still retain values. see code below:
public class helloandroid extends activity { private static int mvalue; // static member here public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); textview tv = new textview(this); tv.settext((mvalue != 0) ? ("left-over value = " + mvalue) : "this new instance"); setcontentview(tv); } public void ondestroy() { super.ondestroy(); mvalue++; }
}
the above code displays left-over value in mvalue, , increments when session ends know sure ondestroy() called.
i found useful answer on forum, , understand in above code mvalue class member, instead of instance member. isn't true that, in particular case, have 1 single helloandroid activity, , when dies, cleaned up, , next time come back, starts on again? (or, there other misterious thing in system still holds on after ondestroy() won't die???)
(the above variable, if it's bunch of objec references? each piece separately re-collectable memory. there chance gc collects of them not all-or-none? bugs me.)
the os decides when things "go away." ondestroy
there let app have final chance clean things before activity destroyed not mean activity will, in fact, gced. here good article recommend people read relates creating exit button. while it's not asked about, concepts understand what's going on.
Comments
Post a Comment