我希望AlarmManager
每天上午10:30根據用戶移動設備時間被解僱。它確實在上午10點30分發射,但問題在於上午10點30分之後,它會在每半小時或任何不尋常的時間間隔之後重複沒有時間。
如何預防此問題?我在成功登錄並註冊ButtonCick()
事件時致電此問題。如果用戶註銷,我也想停止此操作。
我的代碼如下:AlarmManager不能及時開火
Intent myIntent = new Intent(Register.this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Register.this,
0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar firingCal = Calendar.getInstance();
Calendar currentCal = Calendar.getInstance();
firingCal.set(Calendar.HOUR_OF_DAY, 10);
firingCal.set(Calendar.MINUTE, 30);
firingCal.set(Calendar.SECOND, 0);
long intendedTime = firingCal.getTimeInMillis();
long currentTime = currentCal.getTimeInMillis();
if (intendedTime >= currentTime) {
WakeLocker.acquire(getApplicationContext());
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
WakeLocker.release();
} else {
WakeLocker.acquire(getApplicationContext());
firingCal.add(Calendar.DAY_OF_MONTH, 1);
intendedTime = firingCal.getTimeInMillis();
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, intendedTime,
AlarmManager.INTERVAL_DAY, pendingIntent);
WakeLocker.release();
}
你的targetSdkVersion是什麼? – user2450263
targetSdkVersion是19 –