The standard StartReceiverAt is inexact, in order to allow the OS to make optimizations. Worth reading: https://developer.android.com/training/scheduling/alarms Exact scheduling: 1. AddPermission(android.permission.SCHEDULE_EXACT_ALARM) 2. Private ion As Object - class global 3. Private...
www.b4x.com
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?
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.