android - 为什么 AlarmManager.setRepeating 中的 triggerAtTime 不起作用

标签 android

AlarmManager mgr=
      (AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
  Intent i=new Intent(ctxt, AlarmReceiver.class);
  PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0);
mgr.setRepeating(
  AlarmManager.ELAPSED_REALTIME_WAKEUP,
  System.currentTimeMillis() + 1000,
  1000, pi);

根据安卓文档

triggerAtMillis time in milliseconds that the alarm should first go off, using the appropriate clock (depending on the alarm type).

Action 应该在 1 秒后立即开始,但它从未被调用,为什么?

最佳答案

在 setRepeating() 方法中不要使用 AlarmManager.ELAPSED_REALTIME_WAKEUP,而是使用 AlarmManager.RTC_WAKEUP,如下所示,

mgr.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 1000, 1000, pi);

关于android - 为什么 AlarmManager.setRepeating 中的 triggerAtTime 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13412685/

相关文章:

android - 蜂窝网络中的 RLC 协议(protocol)。有没有办法控制应用程序内使用的模式?

Android 媒体播放器仅播放一次声音

android - 使用 Canvas

Android & Servers - 可以用什么服务器软件,一头雾水

java - 如何使用 SharedPreferences 检查用户是否正在使用应用程序?

java - 无法从 firebase 数据库中检索值

android - Firestore 更新查询未执行

android - ScrollView 内的 Google Maps API v2 SupportMapFragment - 用户无法垂直滚动 map

android - view.getViewTreeObserver().addOnGlobalLayoutListener 泄漏 fragment

android - 位图的 Parcelable 相关大小是多少?