有谁知道如何做贪睡功能以及我哪里出错?
我的默认贪睡时间是5分钟。它工作正常,直到重新开始 应用程序然后再也不起作用。 如果我清除缓存和数据再次起作用。
public void onClick(View view) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
int iSnoozeLeft = settings.getInt(PuzzleAlarm.SNOOZE_LEFT, 1);
if (iSnoozeLeft != 0) {
Intent activate = new Intent(AlarmNotification.this, AlarmReceiver.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(AlarmNotification.this, 0, activate, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
int iMinutes = Preferences.getSnooze(settings, AlarmNotification.this);
Calendar calendar = Calendar.getInstance();
calendar.roll(Calendar.MINUTE, iMinutes);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
SharedPreferences.Editor editor = settings.edit();
editor.putInt(PuzzleAlarm.SNOOZE_LEFT, iSnoozeLeft - 1); // disabling
// Commit the edits!
editor.commit();
}`
答案 0 :(得分:0)
PendingIntent.getBroadcast(AlarmNotification.this, 0 ,激活,0);
确保您没有使用“0”作为其他警报ID。在其他情况下,您的“贪睡”代码将覆盖之前的警报。