且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在使用RTC报警Android上使手机的睡眠

更新时间:2023-02-26 21:47:59

  

为什么我的业务执行?

presumably别的东西是具有设备醒着的时刻。

  

如果另一个服务行为不正常,并使用报警_WAKEUP变体将我的服务醒过?

是的,尽管行为不端是在旁观者的眼睛。

  

我能否避免被唤醒另一个服务,并转动屏幕上的用户只要醒了吗?

不是直接通过 AlarmManager 。你可以看的 ACTION_SCREEN_OFF ACTION_USER_ preSENT 广播,也许禁用那些与你的报警。

I've been seeing some strange issues using the Alarm manager in Android, despite the fact that I'm using RTC (non Wakeup) the phone will reliably send the PendingIntents on the correct repeating intervals.

Details of my test

  • Device is not charging, just sitting on my nightstand while I slept
  • My service woke up on its repeat interval (30 minutes, an extreme I know) EVERY TIME
  • The service logged its activity in a file so I could read it in the morning

Now from my understanding the phone should be sleeping unless I wake it up and my Alarms should not be sent until the phone is awake.

  • Why was my service executing?
  • If another service is misbehaving and using the _WAKEUP variants of the alarm will my service wake up too?
  • Can I avoid being woken by another service, and just awake from the user turning the screen on?

Why was my service executing?

Presumably something else was having the device awake at those moments.

If another service is misbehaving and using the _WAKEUP variants of the alarm will my service wake up too?

Yes, though "misbehaving" is in the eye of the beholder.

Can I avoid being woken by another service, and just awake from the user turning the screen on?

Not directly via AlarmManager. You can watch for ACTION_SCREEN_OFF and ACTION_USER_PRESENT broadcasts, and perhaps disable your alarms between those.