A singleton will live as long as an Application (until the process is
killed).  It may be created later, since it isn't created until needed, so
that is a bonus feature.

Good point about onLowMemory(); that is only available by subclassing a
context (either an activity, service, or application).

On Mon, Nov 8, 2010 at 10:27 PM, joebowbeer <[email protected]> wrote:

> Is there any difference in lifetime/scope between a custom Application
> and a singleton class?
>
> My understanding, based on previous postings in this group, is that
> the class loader (singleton) has the same lifetime as its process, and
> that a single process may be reused by subsequent instances of an app.
> Is this correct? If so, then the singleton may "live" longer than the
> analogous custom application instance, right?
>
> Another apparent advantage of the custom Application is the
> onLowMemory method. Is this actually useful in practice? As I recall,
> Application.onTerminate is not called reliably.
>
> On Nov 1, 3:02 pm, Dianne Hackborn <[email protected]> wrote:
> > Yes the application object is always created before any other of your
> > components in the process.
> >
> > There is no need to use the application class to implement singletons
> (that
> > part of the docs is totally wrong, I just put in a change to get rid of
> it).
> >  I suggest avoiding that entirely and just write a singleton without it.
> >
> > On Mon, Nov 1, 2010 at 3:49 PM, Federico Paolinelli <[email protected]
> >wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > In a book I read, the author suggests to extend the application class
> > > in order to have a place to be used as a singleton. In this way, it is
> > > easy to make some initialization stuff in it onCreate().
> >
> > > Now my question: if my application has also some broadcast receivers
> > > declared in the manifest, and the application was not started
> > > explicitly, or it was but then the os reclaimed it resources back,
> > > what will be happening if the broadcast receiver is triggered? Will
> > > the onCreate of the application class be called first?
> >
> > > Thanks in advance,
> >
> > > Federico
> >
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to
> [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-developers%[email protected]><android-developers%2Bunsubs
> [email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > [email protected]
> >
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see
> and
> > answer them.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to