AlarmManager and WakeLock example

2019-08-24 14:00发布

I tried this wakefull example:https://github.com/commonsguy/cw-omnibus/tree/master/AlarmManager/Wakeful

But I have a few questions.

Do I need <action android:name="android.intent.action.BOOT_COMPLETED" />? because the intent is always null, as I tested.

And inScheduledService is:

@Override
    protected void doWakefulWork(Intent intent) {
        Log.d(getClass().getSimpleName(), "I ran!");
    }

But this method is never fired.

In WakefulintentService there is this method, which is also never fired:

 @Override
    final protected void onHandleIntent(Intent intent) {
        try {
            doWakefulWork(intent);
        } finally {
            PowerManager.WakeLock lock = getLock(this.getApplicationContext());

            if (lock.isHeld()) {
                lock.release();
            }
        }
    }

What to change, so that i will get I ran as output?

标签: android
1条回答
时光不老,我们不散
2楼-- · 2019-08-24 14:48

Do I need ?

Only if you wish to set up your alarms again after a reboot. By default, alarms are wiped out when the device reboots.

but this method is never fired.

Yes, it is. You can tell this by running the project.

in WakefulintentService is this method which is also never fired:

Yes, it is. You can tell this by running the project.

For example, here is the output of a run I just did now:

12-11 14:03:05.671: D/ScheduledService(3322): I ran!
12-11 14:03:10.671: D/ScheduledService(3322): I ran!
12-11 14:03:15.671: D/ScheduledService(3322): I ran!
12-11 14:03:20.671: D/ScheduledService(3322): I ran!
查看更多
登录 后发表回答