我的意思是,如果我有一个AlarmManager,并且可以每隔1:00、4:00、10:00执行一次AlarmManager,那么触发一次以上的AlarmManager (不仅仅是1:00或4:00或10:00 )是否可行?还是有其他的建议?
如果是,你能用密码解释一下吗?
这是我的代码,这只是每12点执行一次
public static void InitLoggingService(Context context) {
boolean bolLoggingServiceState = UtilitiesPreferences.GetLoggingServiceState(context);
Intent _Intent = new Intent(context, ServiceMain.class);
Intent SaveFileIntent = new Intent(context, ServiceLogger.class);
PendingIntent SaveFilePending = PendingIntent.getService(context, 0, SaveFileIntent, 0);
AlarmManager _AlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar _Calendar = Calendar.getInstance();
_Calendar.set(Calendar.HOUR_OF_DAY, 12);
if (bolLoggingServiceState == true){
context.startService(_Intent);
_AlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, _Calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, SaveFilePending);
}else{
context.stopService(_Intent);
InitStarterService(context);
_AlarmManager.cancel(SaveFilePending);
}
}发布于 2014-08-19 07:03:12
是的,在很大程度上,possible.It似乎不需要告诉您编写服务和接收程序的情况,从上面的代码中我猜您已经做过了。我会告诉你实现你想要的东西的逻辑。
很少需要做的更改是每次alarmmanager触发时调用它,即取消先前的警报并启动一个新的one.In,换句话说,每当您的服务被调用“启动新警报”时,将警报配置为只执行once.So。
在mobile.Save上设置一个本地db,在同一个表中设置一个字段,该字段将通知您上次执行的时间间隔。然后每次从db读取新的报警呼叫间隔并相应执行。
https://stackoverflow.com/questions/25376832
复制相似问题