AlarmManager
이 사용자 모바일 장치 시간을 기준으로 매일 오전 10시 30 분에 발생하도록하고 싶습니다. 오전 10시 30 분에 화재가 발생하지만 문제는 오전 10시 30 분 이후로 매 30 분마다 또는 비정상적인 시간 간격 후에도 시간없이 반복됩니다.
이 문제를 방지하려면 어떻게해야합니까? Successfull 로그인 및 등록 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은 –