Android Question Alarms - 3 services with differnt times -Please help me

M.LAZ

Active Member
Licensed User
Longtime User
Hello

i'm not an expert, i have lost alot of time ,who can help me?


Notes :
1- when restart the device , alarm runs automatically.( How to avoid that?)
2- when press back key, scheduled alarm doesn't run in the detected time.
3- when the screen locked , scheduled alarm don't work.
4- when alarm is on , how to call the Main activity and act2 activity
because (act2 => to display Alarm Screen) as soon as user press back key
the main Activity Activate, if the user press back key again,must be
scheduled alarms still continue runing for the next alarms and next days for ever in background.

ohuuuuuuuuuuufffffff :(:(:(:(:(

Thank you in advance,:):)
 

Attachments

  • ex.zip
    236.4 KB · Views: 168
Last edited:

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Dim dt As Long = DateTime.Now
    Dim destdt As Long = dt + DateTime.TicksPerDay
    Log("start="&DateTime.Date(dt))
    Log("end="&DateTime.Date(destdt))
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
B4X:
    Dim dt As Long = DateTime.Now
    Dim destdt As Long = dt + DateTime.TicksPerDay
    Log("start="&DateTime.Date(dt))
    Log("end="&DateTime.Date(destdt))


thank u Mr Don, yes that's to get the next date or day ... where i can put this code ? in a timer and what is the timer interval?
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
When you work with services you can avoid the use of the timer.
It's much easier to use StartServiceAt and schedule when the next service will start.
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
And this is the code which calculates the next task (tomorrow at midnight + 1 minute)
It uses the standard DateUtils library


B4X:
    Dim dateNow As Long = DateTime.Now
    Dim NextTask As Long
    Dim m As String
    Dim p As Period
    NextTask=dateutils.SetDateAndTime (DateTime.GetYear(datenow) ,DateTime.GetMonth (datenow),DateTime.GetDayOfMonth(datenow),0,1,0)
    p.Days =1
    NextTask=DateUtils.AddPeriod (NextTask,p)
    'In NextTask you have 'tomorrow' at midnight and 1 minute
    'The next code will Log the result (ok, probably was easier with a Format...
    m=DateUtils.GetDayOfWeekName(NextTask) &  " " & DateTime.GetDayOfMonth(NextTask) & " " & DateUtils.GetMonthName(NextTask) & " " & DateTime.GetYear(NextTask)
    m=m & "  " & DateTime.GetHour (NextTask) & ":" & DateTime.GetMinute(NextTask) & ":" & DateTime.GetSecond (NextTask)
    Log("NextTask:" & m)
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
using your code, everytime I start the app, I've got a notification. How can I prevent it?
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
If you parse the code (place a breakpoint in activity start and the go on with F8) you'll see that in that demo I do a notification at every start. I know it's annoying but it was a good example. Just search the notify and cut the one you want to avoid. I don't have the code here now, so I cannot completely help you.
 
Upvote 0

Straker

Active Member
Licensed User
Longtime User
But do you mean the code above this thread?
No, sorry (we're talking about similar things in 2 or 3 threads)

If you mean the code of post #7, it just evaluate the next task and doesn't call any notification.
Probably your code performs a notification at startup. Where are your notification? In the service? From the activity, are you calling the service with StartService or sStartServiceAt?
 
Upvote 0

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
The notification is in a module. I start the service at the "FIRST TIME" of the Main Activity. But, if I close the app, and reopen it, the service start and also the notification
 
Upvote 0
Top