标签:android开发
你可以存储单个字节来表示你的需要调度的周,拉用按位与运算值出来。第1位可以代表星期一,第二位 星期二,或者你可以用它来代表天的所有组合,例如:
01100000 - Saturday/Sunday (Weekend)
01110001 - Friday/Saturday/Sunday/Monday (Long weekend)
你需要通过如下方式进行读取值
byte val = 0x71; //01110001
boolean mondayActive = (val & 0x1) == 1;
boolean fridayActive = (val >> 4& 0x1) == 1;
这是假设你已经熟悉AlarmManager和正在寻找一种机制来跟踪你的报警,你不能用一个单独的报警安排在OP中描述的方式活动。如果你需要模仿的cron在一个单独的任务,可能是看看类似的BuzzBox的SDK。
EDIT write sample
public static final int MONDAY = 0x01; //00000001
public static final int TUESDAY = 0x02; //00000010
public static final int WEDNESDAY = 0x04; //00000100
public static final int THURSDAY = 0x08; //00001000
public static final int FRIDAY = 0x10; //00010000
public static final int SATURDAY = 0x20; //00100000
public static final int SUNDAY = 0x40; //01000000
//example values to write
int weekend = SATURDAY | SUNDAY; //01100000
int longWeekend = FRIDAY | SATURDAY | SUNDAY | MONDAY; //01110001
//and as per flightplanner‘s comment, to read
boolean mondayActive = (weekend & MONDAY) == MONDAY; //false
m
mondayActive = (longWeekend & MONDAY) == MONDAY; //true
原文地址:http://www.itmmd.com/201410/33.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。
标签:android开发
原文地址:http://blog.csdn.net/androidmylove/article/details/42024313