AlarmManager不会触发android警报

AlarmManager不会触发android警报,android,alarmmanager,Android,Alarmmanager,我的应用程序中有这个警报设置功能,用户可以在目标的每个活动上设置警报。该功能在我设置的最初几次警报时起作用,但在那之后,它就不再触发警报了。我不知道为什么。我认为这与经理有关。我找不到解决这些问题的任何途径 这是我的代码: public class AlarmManagerBroadcastReceiver extends BroadcastReceiver { MyDBAdapter dbhandler; @Override public void onReceiv

我的应用程序中有这个警报设置功能,用户可以在目标的每个活动上设置警报。该功能在我设置的最初几次警报时起作用,但在那之后,它就不再触发警报了。我不知道为什么。我认为这与经理有关。我找不到解决这些问题的任何途径

这是我的代码:

public class AlarmManagerBroadcastReceiver extends BroadcastReceiver {

    MyDBAdapter dbhandler;

    @Override
    public void onReceive(Context context, Intent intent) {


        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "YOUR TAG");

        //Acquire the lock
        wl.acquire();

        //You can do the processing here.
        Bundle extras = intent.getExtras();
        StringBuilder msgStr = new StringBuilder();


        //Release the lock
        wl.release();
    }

    public void SetAlarms(Context context, int goal_id)
    {
        dbhandler = new MyDBAdapter(context);

        AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        List<Activities> allActs = dbhandler.getAllActivitiesByGoal(goal_id);


        for (final Activities act : allActs) {

            //for alarm
            //Create an offset from the current time in which the alarm will go off.

            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(System.currentTimeMillis());
            cal.set(Calendar.DATE, Integer.parseInt(act.getEDay()));  //1-31
            cal.set(Calendar.MONTH, Integer.parseInt(act.getEMonth()) - 1);  //first month is 0!!! January is zero!!!
            cal.set(Calendar.YEAR, Integer.parseInt(act.getEYear()));//year...

            cal.set(Calendar.HOUR_OF_DAY, act.getHour());
            cal.set(Calendar.MINUTE, act.getMinute());
            cal.set(Calendar.SECOND, act.getSecond());
            cal.set(Calendar.MILLISECOND, act.getMillisecond());
            //MessageTo.message(SetNotifyActivity.this, hour+":"+minute+" "+format);

            //assigned a unique id to notifications


            //Create a new PendingIntent and add it to the AlarmManager
            Intent intent3 = new Intent(context, ViewTasksActivity.class);
            intent3.putExtra("goalid", Integer.toString(goal_id));
            intent3.putExtra("activityId", Integer.toString(act.getActId()));
            intent3.putExtra("activityName", act.getActivityName());
            intent3.putExtra("show", "true");
            PendingIntent pendingIntent = PendingIntent.getActivity(context,
                    act.getActId(), intent3, PendingIntent.FLAG_CANCEL_CURRENT);


            am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                    pendingIntent);
        }
    }

    public void CancelAlarms(Context context, int goal_id)
    {
        dbhandler = new MyDBAdapter(context);

        List<Activities> allact = dbhandler.getAllActivitiesByGoal(goal_id);

        for (final Activities act : allact) {
            Intent intent = new Intent(context, ViewTasksActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context,
                    act.getActId(), intent, PendingIntent.FLAG_CANCEL_CURRENT);
            AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

            am.cancel(pendingIntent);
        }
    }

}
公共类AlarmManagerBroadcastReceiver扩展广播接收器{
MyDBAdapter-dbhandler;
@凌驾
公共void onReceive(上下文、意图){
PowerManager pm=(PowerManager)context.getSystemService(context.POWER\u服务);
PowerManager.WakeLock wl=pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,“您的标签”);
//获得锁
wl.acquire();
//您可以在这里进行处理。
Bundle extras=intent.getExtras();
StringBuilder msgStr=新的StringBuilder();
//松开锁
wl.释放();
}
公共void SetAlarms(上下文上下文,int-goal_-id)
{
dbhandler=newmydbadapter(上下文);
AlarmManager am=(AlarmManager)context.getSystemService(context.ALARM\u服务);
列出allActs=dbhandler.getAllActivitiesByGoal(目标id);
(最终活动法:allActs){
//报警
//创建一个与报警将关闭的当前时间的偏移量。
Calendar cal=Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.DATE,Integer.parseInt(act.getEDay());//1-31
cal.set(Calendar.MONTH,Integer.parseInt(act.getEMonth())-1);//第一个月是0!!!一月是零!!!
cal.set(Calendar.YEAR,Integer.parseInt(act.getEYear());//年。。。
cal.set(Calendar.HOUR,OF_DAY,act.getHour());
cal.set(Calendar.MINUTE,act.getMinute());
cal.set(Calendar.SECOND,act.getSecond());
cal.set(Calendar.millis秒,act.getmillis秒());
//MessageTo.message(SetNotifyActivity.this,小时+“:“+分钟+”+格式);
//为通知分配了唯一的id
//创建新的PendingEvent并将其添加到AlarmManager
Intent intent3=新的Intent(上下文,viewstasksactivity.class);
intent3.putExtra(“goalid”,Integer.toString(goal_id));
intent3.putExtra(“activityId”,Integer.toString(act.getActId());
intent3.putExtra(“activityName”,act.getActivityName());
意图3.额外(“显示”、“真实”);
PendingEvent PendingEvent=PendingEvent.getActivity(上下文,
act.getActId(),intent3,PendingEvent.FLAG_CANCEL_CURRENT);
am.set(AlarmManager.RTC_唤醒,cal.getTimeInMillis(),
悬挂式);
}
}
公共无效取消报警(上下文上下文,int-goal\u-id)
{
dbhandler=newmydbadapter(上下文);
列出allact=dbhandler.getAllActivitiesByGoal(目标id);
(最终活动法:allact){
意向意向=新意向(上下文、ViewTasksActivity.class);
PendingEvent PendingEvent=PendingEvent.getActivity(上下文,
act.getActId(),intent,PENDINGENT.FLAG_CANCEL_CURRENT);
AlarmManager am=(AlarmManager)context.getSystemService(context.ALARM\u服务);
上午取消(挂起);
}
}
}
谢谢你的帮助。:)