Android Question Setting daily multiple reacuring alarm

Discussion in 'Android Questions' started by Noel, Feb 14, 2015.

  1. Noel

    Noel Member Licensed User

    I've been searching some time now, but till now with no luck.

    I would like to set daily multiple recurring alarms.
    03:00, 03:15, 06:00, 06:15, 09:00, 09:15, 12:00, 12:15 ......

    Till now I've been trying this by comparing "DateTime.Time" and when the same, trigger the alarm.
    Unfortunately (for me) DateTime.Time is in Epoch/Unix format.
    ie: 1423940165 month/day/year/hours/minutes/seconds.
    As it's a daily returning alarm I do not really need month/day/year.

    What would be a proper way of doing this be?
    Small code example would be great!

    Thank you.
  2. Erel

    Erel Administrator Staff Member Licensed User

    B4A (and Java) ticks values are not the same as unix time.

    You first need to learn how to use StartServiceAt to schedule a single alarm. Once you learn how to use it you need to store all the alarm times in a database or file and then schedule the next alarm each time (you can only schedule one alarm at a time).
  3. Noel

    Noel Member Licensed User

    I've already got a working version using StartServiceAt.
    Only problem I'm stuck with now is that it will only trigger the alarm when DateTime.Time = 1423940165 (example)

    I would like to trigger it when DateTime.Time = 18:56:05 and not 2/14/2015/18:56:05

    I guess I could convert the Epoch time back, do a trim on it to remove the month, day, year, and than do a compare..

    Anyway.. I'll do some more reading and keep trying.
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can use DateTime.TimeParse to get the time instance with today's date. You then need to check whether the time has passes or not. If it already passes then add a day to the result (with DateUtils.AddPeriod or DateTime.AddDate).
  5. Noel

    Noel Member Licensed User

    Thank you. That sounds like an easer way of doing things.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice