Android Repetitive alarm scheduling problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.