重复计划任务在Android SDK中报警经理选择天 [英] Repeat scheduled tasks on selected days in Android sdk alarm manager

查看:105
本文介绍了重复计划任务在Android SDK中报警经理选择天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点,而不会打扰专家和在这里和其他网站上看过无数的线程。这显然​​是我的大脑不理解需要为了做这个工作的。

我的目标是,该应用允许用户输入一个时间,并在一个星期的一天或多天。所有的GUI一侧的日期和时间我已经做了的存储,然而得到警报管理重复,让在14:00说,每星期一,然后可以在14:02发出。我已经使用了Java日历对象以保存一周的时间和日期或者甚至用该月的星期的日期和星期。这些然后,根据需要,转换为毫秒为它由报警管理器读取

然后我已使用,也可以报警管理器中设置或设置重复的方法重复事件。所有我能够做的就是,如果我更改仿真器的日期和时间周一又没有发生一次,然后就发生了。

该GUI持有小时和分钟所需的变量,然后将这些都对日历对象使用。

报警管理要求事件发生的广播接收机。

请能有人干脆就如何设置特定的日子,如周一,周三周五的例子。我知道,都需要每一天,在我刚才专注于周一作为我的主要测试的那一刻独立的报警管理。

链接查看:


现在管理算出这个所以我如下的回答:

以下code计算现在需要的调度任务的日间剩下的日子。变量whichday从该code属于方法通过参数传递。在这种认识whichday通过重新presents每周1天〜7,其中1是周日,2是星期一等等。

  //这得到了一周的当前日期作为今日/ NOW
INT checkcurrentday = getcurtime.get(Calendar.DAY_OF_WEEK);//这个计算现在需要的是重新通过whichday psented $ P $一天的日子。
INT NUMBEROFDAYS = Calendar.SATURDAY + whichday - checkcurrentday;//现在不加的天差设为您的Calendar对象
tMondayOn.add(Calendar.DATE,NUMBEROFDAYS);


那么,你需要首先使用Java日历API(或乔达!)找出当下周一。设置闹钟到时间(毫秒),然后使用setRepeating并传递一个长的时间重新presents一个星期的时间间隔。

I have tried to do this without bothering the experts and have read numerous threads here and on other sites. It is clearly my brain not understanding what needs to be done in order for this to work.

My goal is that the app allows the user to enter a time and one or more days in a week. All of the GUI side and storing of the dates and times I have done, however to get the alarm manager to repeat, lets say every Monday at 14:00 and then can send at 14:02 . I have used the java Calendar object to hold the times and days of the week or even used date and day of the week of the month. These are then , as needed, converted to milliseconds for it to be read in by the alarm manager.

I then have used either the alarm manager set or set repeat methods to repeat the event. All I am able to do is get it to occur once and then if I change the emulator date and time to another Monday nothing happens.

The GUI holds the hours and minutes in required variables and then these are used against the calendar objects.

The alarm manager calls a broadcast receiver for the event to occur.

Please can someone simply give an example on how to set specific days such as Monday , Wednesday Friday. I know that separate alarm managers are needed for each day and at the moment I have just focused on Monday as my main test.

Links viewed:


Managed to figure this out now and so follows my answer:

The following code calculates the remaining days between now and the day needed for the scheduled task. the variable whichday is passed via parameter from the method this code belongs to. In the understanding of this whichday represents days of the week 1 through to 7 where 1 is Sunday , 2 is Monday and so .

//This gets the current day of the week as of TODAY / NOW
int checkcurrentday = getcurtime.get(Calendar.DAY_OF_WEEK);

// This calculates the days between now and the day needed which is represented by whichday.
int numberofdays = Calendar.SATURDAY + whichday - checkcurrentday;

//Now add NOT set the difference of the days to your Calendar object
tMondayOn.add(Calendar.DATE, numberofdays);

解决方案

Well, you need to first use the Java Calendar API (or Joda!) to figure out when the next monday is. Set the alarm to to that time in milliseconds then use setRepeating and pass in a long that represents the interval of one week.

这篇关于重复计划任务在Android SDK中报警经理选择天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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