AlarmManager
事前定義された時間に実行するタスクをスケジュールするために使用しようとしています。これAlarmManager
はアプリケーションから初期化され、バックグラウンドで実行されます(これは正常に実行されます)。メソッドBroadcast
内でイベントが受信されると、その内部をonReceive()
使用してサービスを呼び出し、「15分後に」と言うようにcontext.startService(webServiceIntent);
これを再スケジュールしようとしています。PendingIntent
しかし、いくつかの理由でそれは機能していません。それはすべてそれを停止しPendingIntent
ます。
以下は関連する情報源です。
//Initiliazing AlarmManager from my app
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getBroadcast(this, 0, getLocationPollerIntent(), 0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), Constant.LOCATION_POLLING_PERIOD, pendingIntent);
//onReceive Method of BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent) {
Intent webServiceIntent = new Intent(context, LocationNotificationService.class);
webServiceIntent.putExtra("UPDATED_LOCATION", loc);
context.startService(webServiceIntent);
}
//Inside LocationNotificationService to reschedule the PendingIntent - This PendingIntent never get called
protected void onHandleIntent(Intent intent) {
c.set(Calendar.HOUR_OF_DAY, 13);
c.set(Calendar.MINUTE, 35);
c.set(Calendar.SECOND, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, getLocationPollerIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, c.getTimeInMillis(), Constant.LOCATION_POLLING_PERIOD, pendingIntent);
}