Reputation: 2061
Unexpectedly I realized that my static class members are retained after application is finish (after onDestroy() is called). Static members initializations are ignored in next application instantiation. Is it normal or it is only a bug in emulator? I can't find anything about it in documentation. Do they specify anything connected to this behavior?
Additional comments: When I have two fields in activity, static and non static like this:
static String s1 = new String("s1");
String s2 = new String("s2");
...and destroy and start application again, the first initializer is not executed and the second one is executed. Where is the sense? For me it violates language rules.
Upvotes: 3
Views: 1243
Reputation: 10352
When an application starts, its own vm is started and the main activity is started. When that activity is left (eg. back button pressed or you call finish()) onDestroy() is executed.
While that technically ends your application your application process and vm is still running. That includes running threads.
So all static members remain intact. The system can kill the vm once it requires more memory at any time while it is not showing.
Upvotes: 0
Reputation: 160211
onDestroy
doesn't mean the application's processes are being killed, or that the class itself destroyed/unloaded, it's destroying an activity instance.
Upvotes: 2