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()。 –