I am building an application which triggers an alarm via AlarmManager.
I would like to be able to call the Alarm via it\'s own non-activity class, but since I am not
Service
and Activity
inherit from Context
- so when you are calling getSystemService
in these classes, you are really calling super.getSystemService
.
If you want to have a Context
available in another class, you can pass one as an argument to a method of that class, keep a reference to it, etc.
Edit: Code sample. But seriously, it is extremely basic - if you understand inheritance and methods.
class MyActivity extends Activity { // Activity extends Context, so MyActivity also extends Context
void someMethod() {
MyOtherClass.useStaticContext(this);
MyOtherClass instance = new MyOtherClass();
instance.useInstanceContext(this.getApplicationContext());
}
}
class MyOtherClass {
static void useStaticContext(Context context) {
}
void useInstanceContext(Context context) {
}
}