|
![]() |
Jeff Verdegan wrote:You mean the "problem" of having to have a context to pass?
Activity and Service both extend Context (indirectly), and ContentProvider has a getContext() method, so in a big chunk of the code we write, the Context is a given. Any other class we write--at least any class that's going to do anything requiring a context--is probably created and/or used by one of those components, so it's easy to give that class a Context.
G. Plann wrote:How do I use getContext to call an external class from any other class?
Any examples or further information to help me understand Context would be great. I come from a VB background and this concept is still not sinking in completely.
G. Plann wrote:Maybe I'm doing something wrong then because in eclipse I don't see a way to create a method, only classes.
I would like to be able to organize my code better like I do in VB by separating the code into methods that are called from my main activity.
I've tried to create classes for just this purpose but I'm always running into these context issues and I don't really understand context or the syntax to use it. Other than this context issue I get along with java just fine.
G. Plann wrote:I'm used to methods and classes being separated in the UI.
...I do understand the syntax for classes and methods. I also have used THIS for context and tried to use getContext ... I guess my issues must be with Android and the way it works with java as you mentioned is a bit different. I am used to OOP where you name it and call to it from anywhere if it is a global. Sometimes java doesn't even feel like an OOP to me with all this context stuff ... If I name it myMethod and it's in the myClass class, I am used to just saying myClass.myMethod(params) and in java it seems like everytime I try and do this it complains about context.
I was hoping for some clarification on the rules of using context. Apparently it is as complicated as I thought.
All my code ends up in one place because of this and I get this thousand line programs to hunt through.
Steve
Steve Luke wrote:
G. Plann wrote:If I name it myMethod and it's in the myClass class, I am used to just saying myClass.myMethod(params) and in java it seems like everytime I try and do this it complains about context.
I gather from this that you don't have a solid grasp on OOP in general or Java to be specific. The last sentence where you talk about myClass.myMethod() causing a complaint about context: this is WAY different than the context stuff you have to think about on Android. The Android Context stuff brought up here is a red herring mentioned because you are in the Android forum and there is a basic assumption about your level of comfort with Java.
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|