android - Access Application Context from class that doesn't extend Activity/Service -


I handle the login in a class for my application which spreads the application. Application is a time when an object of this class Maintains. This means that I can access that specific object from any category which extends the activity or service by calling

  LoginModeller lm = ((LoginModeller) getApplicationContext ());   

However, now I need to reach that object from the object which does not extend the activity or service (nothing is spread). Is there a way to access the app context from a class like this, or do I have to re-do my LoginModeller as a singleton or something else?

Who makes this object? In your constructor, you can pass a pass in context and store it as an instance variable:

  private last reference context; Public MyObject (reference reference) {this.context = context; ...    

Comments