Android Question Confused about scheduling a notification reminder with StartServiceAt

Eric H

Active Member
Licensed User
Longtime User
I have been reading through the forum posts about this topic for over an hour and I am just not getting it...

My app has two checkboxes in the 'reminders options':
1. Notify me to run the app on Wednesdays
2. Notify me to run the app on Fridays

The user can select none, both, or either of these options. The user's preference is saved as two boolean values in a text file inside File.DirInternal.

When the app starts, i read these two values from the text file into a list variable: notificationInfo

I have added a new service module to my project, and I have gathered from the posts I have read so far that I need to use StartServiceAt to schedule my reminder notification (as stated in this post). I have also gathered that since I potentially have more than one time that needs to be scheduled (if the user selects to be reminded on both Wednesday and Friday), that I need to have some code to schedule the next closest task each time it runs (as stated in this post).

I have read the Services tutorial (here), but I can't quite figure out how to get this done. Most of the example code I have come across shows how use StartServiceAt to start a service at DateTime.now+ X number of minutes (or something like this). I did find one or two examples of 'alarm clock' code that did otherwise, but it was not clear enough for me to understand what was going on.

Can someone help clear this up for me (without just linking to another forum post, preferably)

Thanks :)
 

Eric H

Active Member
Licensed User
Longtime User
Does this code make sense for scheduling a notification to happen only on wednesday and friday? And do I need to StopService or just leave it running?

Thanks,
Eric H

B4X:
#Region  Service Attributes 
    #StartAtBoot: True
#End Region

Sub Process_Globals
End Sub

Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)
Dim p As Period
p.Days = 1
Dim tomorrow As Long = DateUtils.AddPeriod(DateTime.Now, p)

Dim wed As Int = 4
Dim fri As Int = 6
Dim today As Int = DateTime.GetDayOfWeek(DateTime.Now)

If today <> wed AND today <> fri Then
    StartServiceAt("", tomorrow, True)
Else
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo("Title", "Message", Main) 
    n.Notify(1) 
End If
 
Upvote 0
Top