Given this strong recommendation against subclassing Application, I'll look to avoid doing so in future projects, but when you say
[subclassing Application] gives you *nothing* you can't do in other, better > ways. the main benefit that comes to my mind is that you can expose static accessors for singletons that need a basic context (nothing more than the application context provides), without being required to pass it in. This occurs frequently in my code - I often have a number of independent static classes that deal with things like image caching. These types of classes invariably need a context during initialization (eg. to open databases or files) even if they don't need them at any later time. Objects within the app that aren't tied to any particular component's lifecycle are often the very same objects that need to interact with caches - ensuring that every such object has access (possibly indirectly of course) to a suitable context with which to access the cache will be a lot of work. In this case, I'm pretty sure that subclassing the Application object is giving me something; it's reducing the amount state that my objects need to carry (state which is almost always redundant since only one call to the accessor will ever need to create the singleton; it also allows me to avoid a synchronized lazy instantiation that would otherwise be necessary for some singletons). I think what's essentially providing this benefit, isn't the subclass of Application per se, but the presence of an reliable event (the call to Application.onCreate in this case) that precedes the instantiation of all other components, and which signals that the availability of the Application context. Without this, everything else carries the burden of providing an initializing context. My understanding of application start-up very incomplete, perhaps it's the provision of such an event (in whatever form) that causes difficulties at a platform level, and/or maybe there's some better way that bypasses the Application class. Tom. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en