安卓:有没有办法阻止AlarmReceiver在BootReceiver解雇 [英] Android: Is there a way to stop AlarmReceiver fired in BootReceiver

查看:507
本文介绍了安卓:有没有办法阻止AlarmReceiver在BootReceiver解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是引导接收器火AlarmManager,使其重复它的任务的每一分钟。我希望用户在应用程序选项启用/是在AlarmManager的每个重复进行禁用操作。到目前为止,我只用了仅仅一个跛脚的解决方案。我的共享preferences和AlarmManager的每个重复我为您在共享preferences用户的preference并在此基础上preference功能要么执行或忽略设置用户的preference。

I am using a Boot receiver to fire AlarmManager,so that it repeats it's task every minute. I'd like the user to have in app option to enable/disable action that is done in every repeat of AlarmManager. So far I only used only a lame solution. I set user's preference in SharedPreferences and in every repeat of AlarmManager I check for user's preference in SharedPreferences and based on this preference the functionality is either executed or ignored.

到目前为止我所知,没有办法从内部自身彻底摧毁AlarmManager。但我可能是错的。

So far to my best knowledge, there is no way to completely destroy AlarmManager from within itself. but I might be wrong.

此外,由于启动接收器是注册在AndroidManifest.xml中和一个BroadcastReceiver只有真正存在时的onReceive被调用时,有可能是没有得到到AlarmManager对象的引用,这样我可以从AlarmManager外面取消报警方式。取消。不过,我可能是错的这一切。

Also, since boot receiver is registered in AndroidManifest.xml and a BroadcastReceiver only really exists when onReceive is called, there is probably no way of getting a reference to AlarmManager object, so that I could cancel the alarm from the outside with AlarmManager.cancel. But I might be wrong about all this.

所以我想问一下,如果我错了这一切,或有某种方式来彻底摧毁/取消AlarmManager上引导启动(从AlaramManager内部,还是外部,无所谓)。有任何想法吗?在此先感谢

So I'd like to ask, if I am mistaken about all this, or if there is some way to completely destroy/cancel AlarmManager started on Boot(from inside the AlaramManager, or outside, doesn't matter). Any ideas? Thanks in advance

推荐答案

您可以通过使用相同的等待意向取消报警的任何时间。

You can cancel the alarm any time by using the same Pending Intent.

Intent intent = new Intent(show.this, TimeAlarm.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(show.this, 0,
                intent, PendingIntent.FLAG_CANCEL_CURRENT);

        <Alarm_Manager_Object>.cancel(pendingIntent);

这篇关于安卓:有没有办法阻止AlarmReceiver在BootReceiver解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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