본문 바로가기

Mobile/Android

[Android] AlarmManager

알람매니저는 일정 시간에 내가 원하는 작업을 수행
AlarmManager am =  (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(MyActivity.this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(MyActivity.this, 0, intent, 0);
or
PendingIntent sender = PendingIntent.getBroadcast(MyActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, sender);
or
and.setRepeating(AlarmManger.RTC, calender.getTimeInMillis(), repeatTime, sender);

알람 정지
am.cancel(sender);