当前位置: 代码迷 >> Android >> AlarmManager 怎么在其他activity中关闭,貌似只能拿到当前设置的PendingIntent才可以关闭
  详细解决方案

AlarmManager 怎么在其他activity中关闭,貌似只能拿到当前设置的PendingIntent才可以关闭

热度:493   发布时间:2016-04-28 04:37:09.0
AlarmManager 如何在其他activity中关闭,貌似只能拿到当前设置的PendingIntent才可以关闭?
AlarmManager 如何在其他activity中关闭,貌似只能拿到当前设置的PendingIntent才可以关闭?


alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                        intent = new Intent(getApplicationContext(), AlarmService.class);
                        pendIntent = PendingIntent.getService(getApplicationContext(), 111,
                                        intent, PendingIntent.FLAG_UPDATE_CURRENT);

                        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm")
                                        .parse("2014-07-15 17:03");
                        Calendar c = Calendar.getInstance();
                        c.setTime(date);

                        alarmMgr.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(),
                                        pendIntent);

alarmMgr.cancel(pendIntent);但是在其他activity拿不到设置的pendIntent,所以无法关闭。不知道大神们有什么好想法以及建议?
------解决方案--------------------
直接new一个, 然后配置成一样的
------解决方案--------------------
在其他Activity中这样执行就可以退出了。

alarmMgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
intent = new Intent(getApplicationContext(), AlarmService.class);
 pendIntent = PendingIntent.getService(getApplicationContext(), 111,
                  intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmMgr.cancel(pendIntent);
  相关解决方案