public static void createAlarms() {
totaltimetaken = totaltimetaken + timetaken;
totalcost = totalcost + costone;
cal = Calendar.getInstance();
//cal.add(Calendar.HOUR, alarmintervalint);
cal.add(Calendar.SECOND, alarmintervalint);
calintent = new Intent(this, AlarmBroadcastReceiver.class);
calpendingintent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345, calintent, 0);
am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, alarmintervalint, calpendingintent);
}
我已将此方法设为静态,因此我可以将其称为同一项目的另一个类。我在这些行上遇到错误:
calintent = new Intent(this, AlarmBroadcastReceiver.class);
calpendingintent = PendingIntent.getBroadcast(this.getApplicationContext(), 12345, calintent, 0);
am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
1) 不能在静态上下文中使用 'this'
2) 不能从类型中对非静态方法 getSystemService(String) 进行静态引用
我将如何解决这些错误?非常感谢!