→ sdyy:取消時 有確定你的pi跟啟動時是一樣的嗎 ? 06/10 22:02
感謝回答,我搞烏龍了,後來發現是我在另一個地方把pi設成null了...
※ 編輯: lovecold (125.224.240.200), 06/10/2014 22:24:56
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.117.44.4
※ 文章網址: http://www.ptt.cc/bbs/AndroidDev/M.1402389325.A.893.html
各位前輩好,小弟我最近在做一個定時的通知,
定時部份都很正常,但是我想取消這個定時器時,卻一直無法取消,
麻煩各位前輩幫幫忙,看看小弟弟我是那裡寫的有問題,下面是程式碼
****************************************************************
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);
*******************************************************************
麻煩各位了,感謝!!!
--