Ok, thanks. That makes sense. I will try changing my code to not to use getApplicationContext()
On Jan 25, 8:37 am, Mark Murphy <[email protected]> wrote: > On Tue, Jan 24, 2012 at 7:27 PM, Zsolt Vasvari <[email protected]> wrote: > > I honestly don't know/remember why.... Let me turn the question > > around, why are you using getApplicationContext()? > > > For example, your sendWakefulWork() looks like this, why? > > > public static void sendWakefulWork(Context ctxt, Intent i) > > { > > getLock(ctxt.getApplicationContext()).acquire(); > > ctxt.startService(i); > > } > > In the end, I am holding onto a WakeLock in a static data member. > > You get a WakeLock by asking for one from the PowerManager. > > You get the PowerManager from a Context. > > Now, it is entirely likely that the WakeLock will never hold a > reference to that Context. But, in case it does, since I'm holding > onto it in a static data member, I want to make sure I'm not leaking a > Context. Since the Application is a natural singleton, I use the > Application to get the PowerManager, to get the WakeLock. > > In this case, it's probably paranoia. > > General rules of thumb: if you are holding onto something possibly > Context-related from a static data member, use the Application > context. Otherwise, don't. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > Android Training in DC:http://marakana.com/training/android/ -- 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

