开发者

Alarm does not work when phone is in deeply asleep

I have an Alarm App that works perfectly except when the phone is deeply asleep.

When truly asleep my alarm activity shows up after the user wakes up the phone. I want the phone to wake up the user...

The app starts my AlarmAcivity directly from a BroadcastReceiver. (Not from a Service.)

One clue:

Log D DeepSleepService: AlarmManager go out of deepsleep

...

PowerManagerService: putReleasedWakeLock

PowerManagerService: *mAcquiredLocks contents****

PowerManagerService: LockList entry : flags=0x10000006 tag=com.solidllc.foo.WakeLock

PowerManagerService: LockList entry : flags=0x1 tag=RILJ

PowerManagerService: LockList entry : flags=0x1 tag=network-location

PowerManagerService: LockList entry : flags=0xa tag=KEEP_SCREEN_ON_FLAG

PowerManagerService: putReleasedWakeLock --> remove partial wakelocks into list, size i

...

//

//My manifest:

android.permission.INTERNET

android.permission.WAKE_LOCK

android.permission.DEVICE_POWER

android.permission.DISABLE_KEYGUARD

The Alarm Clock that comes with Android has the above plus: "Modify global system settings" and "Retrieve Running apps".

Anyone know what can be done?

Thanks much.

Here is the code that sets the alarm:

void armAlarm(int hour, int minute) {

    Calendar alarmtime = new GregorianCalendar();

    alarmtime.set(Calendar.HOUR_OF_DAY, hour);
    alarmtime.set(Calendar.MINUTE, minute);
    alarmtime.set(Calendar.SECOND, 0);

    Intent intent = new Intent(RatActivity.this, AlarmReceiver.class);
    PendingIntent pi = PendingIntent.getBroadcast(RatActivity.this, 0,
            intent, 0);

    AlarmManager am =开发者_StackOverflow中文版 (AlarmManager) getSystemService(ALARM_SERVICE);
    am.cancel(pi);
    am.setRepeating(AlarmManager.RTC_WAKEUP, alarmtime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pi);
}


I figured out what was wrong with my code: In was accessing a database in the BroadcastReceiver.
This is a bad/wrong (as the documentation states).
The fact that it only shows up after a long sleep just makes the bug harder to find.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜