Android安排闹钟周一至周三 - 周五(Android Schedule Alarm Mon - Wed - Fri)
我已经阅读了很多关于如何设置警报的教程。 对于我的项目,我遵循Google提供的代码(下载示例按钮@ https://developer.android.com/training/scheduling/alarms.html )但是每次设置时我的警报都会触发。 这是代码。
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); // Set the alarm to fire at approximately 6:00 p.m., according to the device's // clock, and to repeat mon, wed, fri. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); // Set the alarm's trigger time to 2:49 p.m. calendar.set(Calendar.HOUR_OF_DAY, 14); calendar.set(Calendar.MINUTE, 49); calendar.set(Calendar.SECOND, 00); calendar.set(Calendar.MILLISECOND, 00); int day = 2; while(day < 7){ //2 - monday, 4 - wednesday, 6 friday calendar.set(Calendar.DAY_OF_WEEK,day); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent); day += 2; }
编辑1:昨天我注意到这个闹钟在分钟49,例如14:49,15:59,16:49等每小时都在激活(除了我每次设置)。
I have read a lot of tutorials about how to set up an alarm. For my project I'm following the code provided by Google (Download the sample button @ https://developer.android.com/training/scheduling/alarms.html) however my alarm fires every time I set it. This is the code.
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); // Set the alarm to fire at approximately 6:00 p.m., according to the device's // clock, and to repeat mon, wed, fri. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); // Set the alarm's trigger time to 2:49 p.m. calendar.set(Calendar.HOUR_OF_DAY, 14); calendar.set(Calendar.MINUTE, 49); calendar.set(Calendar.SECOND, 00); calendar.set(Calendar.MILLISECOND, 00); int day = 2; while(day < 7){ //2 - monday, 4 - wednesday, 6 friday calendar.set(Calendar.DAY_OF_WEEK,day); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent); day += 2; }
Edit 1: Yesterday I noticed that this alarm is activating (besides every time I set it) every hour at the minute 49, example 14:49, 15:59, 16:49, etc.
原文:https://stackoverflow.com/questions/26537443
最满意答案
来自Symfony的食谱:
如何嵌入表单集合
http://symfony.com/doc/current/cookbook/form/form_collections.htmlFrom Symfony's cookbook:
How to Embed a Collection of Forms
http://symfony.com/doc/current/cookbook/form/form_collections.html
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我想你不会在用户上保留关于他是什么类型的用户或者他可以是多个用户的参考。 据我所知,你可能想要沿着这些方向做些什么? return $this->getEntityManager()->createQueryBuilder() ->select('sc.contact') //you can add 'c.name' etc but you need to select something from the base table which is school ->f ...
-
来自Symfony的食谱: 如何嵌入表单集合 http://symfony.com/doc/current/cookbook/form/form_collections.html From Symfony's cookbook: How to Embed a Collection of Forms http://symfony.com/doc/current/cookbook/form/form_collections.html
-
如何让symfony 2表单从动态值返回实体(How to get symfony 2 forms to return entities from a dynamic value)[2023-09-18]
我找到了答案,你只需要在表单中添加一个构造函数并从控制器传入客户端,如下所示: //src/LG/ClientBundle/Form/ClientDomainSelectionForm.php namespace LG\ProjectBundle\Form\Projects; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class ClientDomainSelecti ... -
Symfony 3 2实体一种形式(Symfony 3 2 entities one form)[2023-11-13]
Bogdan,你说得对,它不是很干净。 您无需在registerAction中自行设置配置文件,因为它应该由用户实体中的setter完成。 我几乎可以确定你的二传看起来像这样: Class User { setProfile($profile) { $this->profile = $profile; } } 但它一定是这样的: Class User { setProfile($profile) { $this->profile = $profile ... -
请改用EntityType 。 例: $builder->add('twitterSearch', EntityType::class, array( 'class' => TwitterSearch::class, 'choice_label' => 'name', )); Use EntityType instead. Example: $builder->add('twitterSearch', EntityType::class, array( 'class' => Twi ...
-
Symfony表单验证实体(Symfony form validate entity)[2023-02-24]
添加到'CreateUser'表单'cascade_validation'选项以验证嵌套表单,并检查是否在config.yml中指定了约束的注释方法 # app/config/config.yml framework: validation: { enable_annotations: true } Add to 'CreateUser' form 'cascade_validation' option to validate nested forms, and check that's anno ... -
您可以将类型设置为add方法的第二个参数。 class EnrollType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { // ... all your form fields ... $builder->add('account', new AccountType()); } } 这将嵌套您的类型的 ...
-
您使用multiple => true语句呈现所有问题,但这并未将答案与每个问题相关联。 那么你的表单会给出一个答案,所以你只能看到一个答案。 我认为你需要的是一系列表格,请参阅文档: http : //symfony.com/doc/current/form/form_collections.html 首先为每个问题/答案组合构建一个表单,然后从Survey.FormType中呈现表单集合。 You are rendering all questions with the multiple=>true s ...