AlarmManager和激活锁定例子 [英] AlarmManager and WakeLock example

查看:120
本文介绍了AlarmManager和激活锁定例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这wakefull例如: https://github.com/ commonsguy / CW-综合/树/主/ AlarmManager /清醒

不过,我有几个问题。

我是否需要<作用机器人:名字=android.intent.action.BOOT_COMPLETED/> ?因为其目的总是空,因为我测试。

和inScheduledService是:

  @覆盖
    保护无效doWakefulWork(意向意图){
        Log.d(的getClass()getSimpleName(),我跑!);
    }

但这种方法不会解雇了。

在WakefulintentService有此方法,它也从来没有发射

  @覆盖
    最终保护无效onHandleIntent(意向意图){
        尝试{
            doWakefulWork(意向);
        } {最后
            PowerManager.WakeLock锁= GETLOCK(this.getApplicationContext());            如果(lock.isHeld()){
                lock.release();
            }
        }
    }

要改变什么,这样我将获得我跑作为输出?


解决方案

  

我是否需要?


只有当你希望在重启后重新设置你的报警。默认情况下,当设备重新启动报警被消灭。


  

但这种方法不会被解雇了。


是的,是的。您可以通过运行该项目讲这个。


  

在WakefulintentService是这样的方法,还从来没有发射:


是的,是的。您可以通过运行该项目讲这个。

例如,这里是一个运行我刚才做的输出:

  12-11 14:03:05.671:D / ScheduledService(3322):我跑!
12-11 14:03:10.671:D / ScheduledService(3322):我跑!
12-11 14:03:15.671:D / ScheduledService(3322):我跑!
12-11 14:03:20.671:D / ScheduledService(3322):我跑!

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?

解决方案

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!

这篇关于AlarmManager和激活锁定例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆