複数のアラーム マネージャーが異なる時間にインテントを送信するようにスケジュールしました。両方の保留中のインテントに一意の ID、コンテキスト、およびエクストラを渡すように注意しました。以下の関数は、アラーム呼び出しを処理します。.
public void handle(int duration, int id){
Intent intent = new Intent("package.SET");
intent.putExtra ("package.id", Id);
AlarmManager amg = (AlarmManager)Context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pis = PendingIntent.getBroadcast(Context,Id, intent, FLAG_ONE_SHOT);
amg.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, pis); }
アラームを呼び出す2つの機能があります
public void callalarm(int time){
handle(time, UNIQUE_ID1);}
と
public void callalarm2(int time){
handle(time, UNIQUE_ID2);}
ユニーク ID1 と Unique_ID2 が異なることに注意しました。ブロードキャスト レシーバはアラームを処理し、別のコードを実行します。Callalarm1 と callalarm2 が干渉している可能性はありますか。
Androidマニフェストファイルではなく、 registerReceiver 関数を使用してレシーバーを登録しました。
IntentFilter ARFilter = new IntentFilter();
ARFilter.addAction("package.SET");
context.registerReceiver(AR, ARFilter);
ブロードキャスト レシーバーを拡張する AR では、id を使用してアクションを定義します。
public BroadcastReceiver AR= new BroadcastReceiver()
{ public void onReceive(Context context, Intent intent)
{ // i do some stuff here which is confidential
}}
問題は、アラームが遅れることです。遅れている理由はありますか?