질문 그대로, 서비스가 절전 모드에 빠져서 멈추는 걸 염두에 두고 알람매니저에 등록을 하려고 하는데..
private void startKeepAlives() {
Intent i = new Intent();
i.setClass(this,service.class);
i.setAction("IwantAlive");
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
AlarmManager alarmMgr = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1680000,1680000, pi);
}
이렇게 함수를 만들어 놓고, 서비스 클래스에서는 아래와 같이 해보았습니다.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Thread run = new Thread() {
public void run() {
startKeepAlives();
if (running) {
running = false;
Thread test = new Thread(){
이하 생략.
궁금한 점은, 알람매니저에 등록된 서비스가 28분 마다 호출이 될텐데, 저렇게 중복으로 알람매니저를 등록하면 어떤 결과가 나오나요? 한번 등록하든지 100번 등록하든지 28분마다 한번만 실행되는지, 누적될수록 서비스를 여러번 호출하게 되는지 궁금하네요..




PendingIntent에 알람 구분할 수 있게 되어 있는걸로 알고 있어요
저렇게 하면 하나만 호출될거 같은데 앞에꺼가 될지 덮어씌운게 될지는 모르겠네요