Note that there are some explanatory texts on larger screens.

plurals
  1. POContext Cannot be Resolved
    primarykey
    data
    text
    <p>I'm attempting to use a method to schedule monthly alarms described here:</p> <p><a href="https://stackoverflow.com/questions/7568233/how-to-implement-yearly-and-monthly-repeating-alarms">How to implement yearly and monthly repeating alarms?</a></p> <p>However I'm getting two errors on the lines:</p> <pre><code>AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); </code></pre> <p>and </p> <pre><code>PendingIntent sender = PendingIntent.getBroadcast(context, </code></pre> <p>stating "context cannot be resolved" and "context cannot be resolved to a variable" </p> <p>...any suggestions on how this can be resolved?</p> <pre><code> public class Alarm extends Service { // compat to support older devices @Override public void onStart(Intent intent, int startId) { onStartCommand(intent, 0, startId); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // your method to check if an alarm must be fired today PendingIntent sender = PendingIntent.getBroadcast(context, Integer.parseInt(Long.toString(id)), intent, 0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(calendar.getTimeInMillis()); calendar.add(Calendar.SECOND, 30); AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); calendar.add(Calendar.MONTH, 1); am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender); // reschedule me to check again tomorrow Intent serviceIntent = new Intent(Alarm.this, Alarm.class); PendingIntent restartServiceIntent = PendingIntent.getService( Alarm.this, 0, serviceIntent, 0); AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE); // cancel previous alarm alarms.cancel(restartServiceIntent); // schedule alarm for today + 1 day Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); // schedule the alarm alarms.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), restartServiceIntent); } @Override public void onCreate() { // TODO Auto-generated method stub } @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public boolean onUnbind(Intent intent) { // TODO Auto-generated method stub return super.onUnbind(intent); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload