In some of my apps I use a few singleton objects as "managers." I instantiate them in Application.onCreate
and I pass them the ApplicationContext
, which I store in a WeakReference
.
Some of the "manager's" methods start a background task after being called from an Activity
, so I pass the Activity
's context
to the method, and keep a WeakReference
to that as well (and use that inside of an AsyncTask
). That reference is kept until the next time an Activity
calls a method that goes to the background, when the WeakReference
is set to the new Activity
's context
.
My question is, does the ApplicationContext
have to be kept in a WeakReference
, and are there any problems with keeping the Activity
's context
like that?
Activity
'scontext
in an AsyncTask. Am I mistaken? Are there any situation whereApplicationContext
can't be used? If there aren't, I'd much rather switch to usingApplicationContext
(would make my life easier). – Scissor