I need to dispatch a duplicate alarm in my Android project, which could happen on any day, like Monday, like every Thursday, or the next weekend. And you need to save the scheduled period data to the database.
My question is how do I configure and save, my initial idea is to use an int number of seven positions and determine whether an alarm is required based on location.
Is there any other way?
Processing methods
You can store a single byte to represent the week you need to schedule, pull the bitwise AND operation values out. The 1th bit can represent Monday, the second Tuesday, or you can use it to represent all combinations of days, for example:
01100000-saturday/sunday (Weekend)
01110001-friday/saturday/sunday/monday (Long Weekend)
You need to read the values in the following way
byte val = 0x71; 01110001
Boolean mondayactive = (val & 0x1) = = 1;
Boolean fridayactive = (val >> 4& 0x1) = = 1;
It is assumed that you are already familiar with Alarmmanager and are looking for a mechanism to track your alarms, and you cannot use a separate alarm to schedule activities described in Op. If you need to imitate the cron in a separate task, it might be a look similar to the 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
Original address: http://www.itmmd.com/201410/33.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.
Android Repetitive alarm scheduling problem