私はたくさんの場所を検索しましたが、AlarmManagerを使用して毎日特定の時間にサービスを開始する方法(またはそれが不可能な場合はアクティビティ)の明確な順次説明を見つけることができませんでしたか?
そのようなアラームをいくつか登録したいのですが、それらをトリガーするとサービスが開始されます。サービスに小さなコードを入れて実行し、サービスを完全に終了することができます。
Calendar cal = Calendar.getInstance();
Calendar cur_cal = Calendar.getInstance();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Date date = new Date(cur_cal.get(Calendar.YEAR), cur_cal.get(Calendar.MONTH), cur_cal.get(Calendar.DATE), 16, 45);
cal.setTime(date);
Intent intent = new Intent(ProfileList.this, ActivateOnTime.class);
intent.putExtra("profile_id", 2);
PendingIntent pintent = PendingIntent.getService(ProfileList.this, 0, intent, 0);
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pintent);
System.out.println("The alarm set!!");
このコードを試して4.45でアラームをアクティブにしましたが、サービスが起動しませんでした...プロセスを実行し続ける必要がありますか?私は何か間違ったことをしていますか?
もう1つ、次のコードを使用した場合、サービスは完全に実行されます。
long firstTime = SystemClock.elapsedRealtime();
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 30*1000,pintent);