How to use getSystemService in a non-activity class?

You can pass the context to the non-activity class which is the preferred way or you could encapsulate the base context of the application to a singleton which would allow you to access the context anywhere within the application. At some cases this might be a good solution but in others its certainly not a good one.

Anyway, if you want to trigger an alarm via the AlarmManager I’m pretty sure the alarm should inherit from a Service or better yet from IntentService and in such cases you have access to the context via this.getBaseContext() or this.getApplicationContext()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)