내 앱에서 나는 AlarmManager
을 사용하여 매주 특정 시간에 서비스를 시작합니다. 그러나 어떤 경우에는 다른 7 일을 기다리지 않고 다음날 서비스를 요청해야합니다. 그렇기 때문에 나는 알람을 재 설정하지 않고 시작된 서비스에서 새로운 알람을 생성하고 특정 날짜로 설정합니다. 다음과 같은 것 :AlarmManager가 시작한 서비스에서 새 알람 시작
public class AlarmService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//do something
//setting new alarm
AlarmManager alarmMng = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(this,AlarmService.class);
PendingIntent alarmIntent = PendingIntent.getService(this, 0, i, 0);
Calendar c = Calendar.getInstance();
if(something) alarmMng.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis()+1000*60*60*24,alarmIntent);
else alarmMng.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis()+1000*60*60*24*7,alarmIntent);
return START_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
모든 것이 잘 작동하지만 이것이 좋은 방법인지 궁금합니다. 방금 호출 한 서비스에서 새 알람을 만드는 것이 좋은 생각입니까? 나쁜 프로그래밍 연습으로 간주됩니까? 그렇다면 어떻게 처리해야합니까?
글쎄 "할 일"이 대부분 알림을 표시합니다. – matip
내 답변을 편집했습니다. 희망이 도움이됩니다. – Jim
그는 알람 자체로 서비스 일정을 잡으려고했다. 이 알람은 알람 자체가 서비스 내에서 초기화되는 서비스를 시작합니다. –