안드로이드 개발 질문/답변
(글 수 45,052)
Activity의 onCreate에서 알람 리시버를 등록을 합니다.
Intent intent = new Intent("ALARM_ALERT");
intent.putExtra("cmd","alert");
int requestCode = 1;
PendingIntent sender = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
long now = System.currentTimeMillis();
long interval = 10 * 60000;
long startTime = now + interval;
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, startTime, interval, sender);
AndroidManifest.xml에서 "ALARM_ALERT"에 대해서 receiver class name을 주고 있습니다.
Activity 속의 코드에서 receiver의 instance를 만들어서 알람매니저에 등록할 방법은 없나요?




위에서 선언하신 intent 객체에 serializable 객체를 extra로 담아서 설정하면 되기야 하겠지만...
알람은 비동기 처리를 위한 방식인데다가,
해당 변수를 생성한 Activity는 언제든지 시스템에 의해 종료될 수 있고, 새로 생성된 내부 변수는
그 이전의 변수와 다른 레퍼런스일텐데...
올바른 접근법 같지는 않네요~