我需要从活动中获取服务上下文,因为我正在服务中创建警报并且我想在活动中删除它所以必须使用相同的上下文我可以将此服务的上下文保存sharedpreferences
为字符串但是那么如何将此字符串转换为上下文?
我的报警代码是:
Intent intentAlarm = new Intent(getApplicationContext(), TimeAlarm.class);
//add the notification body to the intent:
intentAlarm.putExtra("Notif_body", Notif_Body);
// create the object
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//set the alarm for particular time
alarmManager.set(AlarmManager.RTC_WAKEUP,new GregorianCalendar().getTimeInMillis()+60*1000, PendingIntent.getBroadcast(getApplicationContext(),1,intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
我如何删除它?
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(getApplicationContext(),TimeAlarm.class);
PendingIntent displayIntent = PendingIntent.getBroadcast(getApplicationContext(),1,i, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.cancel(displayIntent);
为什么这不起作用?