私のアラームサービスは、AlarmManagerを使用して、特定の時刻に予定されているイベントについてユーザに通知します。 AlarmManagerが同じサービス(ReminderService)に通知したり、保留中のインテントを捕捉するために別のサービスを開始する必要がありますか?今、このメカニズムは、このアラームをサービスに設定して同じサービスでコールバックを受信
public class ReminderService extends Service {
// ...
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// ..
/* When the alarm goes off the NotifyService will be started. Is it possible to inform **this**
service (ReminderService) and to handle the alarm? */
Intent alarmIntent = new Intent(this, NotifyService.class);
alarmIntent.putExtra(TodoTask.PARCELABLE_KEY, task);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, alarmIntent, 0);
Calendar calendar = Calendar.getInstance();
Date date = new Date(reminderTimeStamp*1000);
calendar.setTime(date);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
}
大丈夫ですが、実際にサービスにデータを格納できないということは、サービスが強制終了される可能性が常にあるためです。いくつかのデータベースリクエストを行う必要があるので、onStartCommandで毎回それらを繰り返す必要がありますか? – null
サービスは、ステータスを確認するために使用できる 'onCreate()'と 'onDestroy()'コールバックを受け取ります。そう、はい、あなたはいくつかのデータを使用する必要がある場合は、ロード/保存する必要があります。 – Budius