mbrc
mbrc

Reputation: 3953

AlarmManager and WakeLock example

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?

Upvotes: 0

Views: 1297

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006539

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!

Upvotes: 1

Related Questions