[問題] AlarmManager該如何取消??

作者: lovecold (小豬頭)   2014-06-10 16:35:23
各位前輩好,小弟我最近在做一個定時的通知,
定時部份都很正常,但是我想取消這個定時器時,卻一直無法取消,
麻煩各位前輩幫幫忙,看看小弟弟我是那裡寫的有問題,下面是程式碼
****************************************************************
PendingIntent pi;
//設定定時器
Activity act = UnityPlayer.currentActivity;
// Schedule the alarm!
AlarmManager am = (AlarmManager)act.getSystemService(Context.ALARM_SERVICE);
Intent ii = new Intent(act, MyAlarmReceiver.class);
ii.putExtra("title", title);
ii.putExtra("content", content);
pi = PendingIntent.getBroadcast(act, ii.hashCode(), ii, 0);
listAMCode.add(ii.hashCode());
am.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() * 10 * 1000, 10*1000, pi);
//取消定時器
AlarmManager am = (AlarmManager)
UnityPlayer.currentActivity.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi);
*******************************************************************
麻煩各位了,感謝!!!
作者: sdyy (中壢市的小智)   2014-06-10 22:02:00
取消時 有確定你的pi跟啟動時是一樣的嗎 ?

Links booklink

Contact Us: admin [ a t ] ucptt.com