【问题标题】:Check if AlarmManager task is in progress检查 AlarmManager 任务是否正在进行
【发布时间】:2017-01-22 16:50:17
【问题描述】:

我正在使用 AlarmManager 运行定期后台任务:

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 10 * 60 * 1000, pendingIntent);

我设置了一个标志PendingIntent.FLAG_UPDATE_CURRENT,但如果我再次运行此代码,我担心它会重新编写我的日程安排。问题:

  • 是否会重置时间,我必须等待 10 分钟才能收到事件?
  • 有没有办法检查我的闹钟任务计划是否已设置?

【问题讨论】:

    标签: java android alarmmanager android-pendingintent android-backup-service


    【解决方案1】:

    它会重置时间,我必须等待 10 分钟才能收到事件?

    是的,它会的。根据文档:

    如果已经为同一个 IntentSender 安排了警报,它将首先被取消

    根据

    有没有办法检查我的闹钟任务计划是否设置好?

    是的,there is 几种解决方案,您可以查看。

    顺便说一句,请注意setRepeating不精确

    注意:从 API 19 开始,所有重复警报都是不准确的。如果您的应用程序需要精确的交付时间,那么它必须使用一次性精确警报,并如上所述重新安排每次。 targetSdkVersion 早于 API 19 的旧版应用程序将继续将其所有警报(包括重复警报)视为准确。

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 2016-09-06
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多