Android's basic components' class loading

2019-03-01 17:43发布

While there are countless resources on Application, Activity etc lifecycle seen from an API perspective (onCreate/Destroy/Whatnot() methods) there is scarcely any information on the actual object's lifecycle for these components from the Java perspective. So for instance I saw (on a YouTube marakana video) that services are basically singletons - and this left me wondering on the state of an IntentService - can it be shared ? Or is this a singleton too ?

I guess initially a process is created (by Zygote ?), along with a DalvikVM instance and then the classes for all components that are declared in the manifest are loaded (?) and then instantiated as needed - but these are guesses. I can't at all answer questions like :

  • are BroadcastReceivers instantiated only once or once each time a broadcast is received ?
  • is Application a singleton ? Guaranteed ?
  • is MyApplication.class loaded before all other components ? Instantiated always ? Even when only a manifest registered BR of mine runs ?
  • when is a particular Application.class of mine (likely to be) unloaded (so I should check if its static fields need initialization (in the case caller initializes them))

You see I am in the dark here. I would like some analysis of the class loading, instantiation and garbage collection of basic android application components - links to docs and/or source welcome. The more technical the better.

Refs : this post by @inazaruk.
Also Static references are cleared--does Android unload classes at runtime if unused?

0条回答
登录 后发表回答