Android's basic components' class loading & _java objects_ lifecycle

落爺英雄遲暮 提交于 2019-12-02 13:09:55

问题


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?

来源:https://stackoverflow.com/questions/19365797/androids-basic-components-class-loading-java-objects-lifecycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!