Tuesday, March 8, 2011

Re: [android-developers] how to use normal class object as context?

You can't do that because getApplicationContext is not a static method of Context.  You need an instance of a Context to call that method, and all it does is return the Context instance that is the Application object for the app (as opposed to, say, an Activity or Service instance).

Doug

On Monday, March 7, 2011 6:31:39 AM UTC-8, Scott McCormack wrote:
I'm still relatively new to this, but this is the second time I've seen this response about a singleton pattern, and I'm still wondering why it wouldn't be simpler to just call...

Context context = Context.getApplicationContext();

... whenever you need a context inside a class that doesn't have one?

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment