0
我对AlarmManager代码:如何从所谓的服务访问到的PendingIntent变量
Intent intent = new Intent(context, MyService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, specialCode, intent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 30 * 1000, operation);
我想访问来自MyService.java的pendingIntent
变量停止重复AlarmManager
怎么可以?
MyService.java
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(condition){
PendingIntent pendingIntent = what?//to access same pendingIntent
G.alarmManager.cancel(pendingIntent);
}
return super.onStartCommand(intent, flags, startId);
}
我想通过'pendingIntent'变量来取消它 当我们把额外给意图,的PendingIntent尚未 – Simon
定义。如比尔解释,你并不需要通过对'服务'的'PendingIntent'的引用。您的服务只需要使用与设置警报时使用的参数相同的参数调用PendingIntent.getService()。 –