手机重启后,设置报警 [英] Setting alarm after phone reboot

查看:180
本文介绍了手机重启后,设置报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我是新来的Andr​​oid和Java,我正在做一个计划,关闭手机声音和变暗在用户选择的时间显示。一切都是通过获取用户输入值(小时和分钟),并设置基于这些值报警火的意图,这将启动从而关闭声音和调暗显示器的服务的广播接收器完成。我想重启后重新启动的报警。我以为我可以简单地设置另一种广播接收器接收BOOT_COMPLETED意图,然后设置报警触发其中一个意图使用一个BroadcastReceiver这之前启动该服务。我的问题是,我不知道如何把价值观从中获取用户输入到由BOOT_COMPLETED意图开始BoradcastReceiver活动。还是有另一种方式来设置的基础上重新启动后,用户输入同样的报警?在简单的话,我想自动设置报警具有相同火时间,这是由用户设定的报警重新启动后。对不起,我的英文不好...

I have a problem. I am new to android and java and I'm making a program which turns off the phone sounds and dims the display at the user selected time. Everything is done by getting user input values (hour and minute) and setting the alarm based on these values to fire an intent to a BroadcastReceiver which starts a service which turns off sounds and dims the display. I want that alarm to be restarted after reboot. I thought that I can just simply set another BroadcastReceiver which receives BOOT_COMPLETED intent and then sets alarm which fires an intent to a BroadcastReceiver used before which starts the service. And my problem is that I don't know how to put the values from the activity which gets the user input to the BoradcastReceiver which is started by BOOT_COMPLETED intent. Or is there another way to set the same alarm based on the user input after reboot? In simply words I want to automatically set the alarm after reboot with the same fire time as the alarm which is set by the user. Sorry for my bad english...

推荐答案

您的做法是正确的。

您需要添加的唯一的事就是坚持它DB或其他地方。每当用户设置的东西,你 AlarmManager 互动,把它也在一个文件。

The only thing you need to add is persisting it in DB or elsewhere. Every time user sets up stuff and you interact with AlarmManager, put it also in a file.

当你得到 BOOT_COMPLETED ,加载数据和设置了所有previously报警。

When you get BOOT_COMPLETED, load data and set all previously alarms up.

这篇关于手机重启后,设置报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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