这是我触发警报的代码
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 :(得分:0)
您正在将待处理意图的标记设置为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);
}