Android Question repeat alarm

f0raster0

Well-Known Member
Licensed User
Longtime User
Hi Team,

I'm trying to set up an alarm that will repeat every 7 days based on this example:

Is this code correct? thanks in advance
B4X:
Private Sub Button2_Click
    Wait For (GetScheduleExactAlarmPermission) Complete (HasPermission As Boolean)
    if HasPermission Then
        StartServiceAtExact(ScheduledReceiver, DateTime.Now + 7 * DateTime.TicksPerDay, True) ' Schedule for 7 days later
    Else
        Log("no permission")
    End If
End Sub

Edit: What is needed to repeatthis alarm every 7 days?
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
you already saw @asales' example: https://www.b4x.com/android/forum/threads/receiver-set-a-repeating-alarm.158157/#content
when the service starts, it sets itself to start again. more important, the example uses a foreground service. both are needed to keep your project running "forever".

technically, it is possible to have the os wake you repeatedly every 7 days to run some job, but i don't think i've seen that implemented in b4a. we use the "self-restart" method show in the example and elsewhere.

if you use a receiver, keep in mind it cannot run a long job. the os will kill it. it would need to run a service. if you started the project with a foreground service, then you've already dealt with half the problem.
 
Upvote 0
Top