这是我触发警报的代码
public void startAlarmp(){
int hour=10;
int minute=30;
Intent alarmIntent2 = new Intent(getApplicationContext(), AlarmReceiver.class);
pendingIntentp = PendingIntent.getBroadcast(getApplicationContext(), 234324243, alarmIntent2, 0);
alertmanagerp = (AlarmManager)getSystemService(ALARM_SERVICE);
alertmanagerp.setRepeating(AlarmManager.RTC_WAKEUP,c1.getTimeInMillis(),24*60*60*1000,pendingIntentp);
}
这是我的AlarmReceiver.java 代码
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//my stuff
}
它只会第一次触发之后就不再重复
并在重复时出现以下错误
D/ActivityThread: setTargetHeapUtilization:0.25
D/ActivityThread: setTargetHeapIdealFree:8388608
D/ActivityThread: setTargetHeapConcurrentStart:2097152
您正在将挂起意图的标志设置为0。尝试将其更改为FLAG_UPDATE_CURRENT
。
pendingIntentp = PendingIntent.getBroadcast(getApplicationContext(), 234324243, alarmIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
编辑。试试这个:
public void startAlarmp(){
int hour=10;
int minute=30;
Intent alarmIntent2 = new Intent(YourActivity.this, AlarmReceiver.class);
pendingIntentp = PendingIntent.getBroadcast(YourActivity.this, 0, alarmIntent2, 0);
alertmanagerp = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alertmanagerp.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 2*60*1000,pendingIntentp);
}