我正在尝试使用AlarmManager
来安排任务在预定义的时间运行。这AlarmManager
是从我的应用程序初始化并在后台运行(运行良好),当在方法Broadcast
内部接收到事件时,我调用一个服务,在其中我试图重新安排它来调用说“15 分钟后”;但由于某些原因它不起作用。它所做的一切就是停止.onReceive()
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);
}