It crashes when resuming when I compile in release mode, but it doesn't crash when I run it in debug(rapid) mode, so I can't get much info on where the problem lies.
It has a main module, a service module and a code module for kvs.
All it does is set an alarm to go off every 30 seconds. If you change the spinner, the notification info in the alarm updates, but the time of the alarm remains the same.
Code is below:
Main module:
Service Module:
kvs module
It has a main module, a service module and a code module for kvs.
All it does is set an alarm to go off every 30 seconds. If you change the spinner, the notification info in the alarm updates, but the time of the alarm remains the same.
Code is below:
Main module:
B4X:
Sub Process_Globals
Dim alarmTicks As Long 'ticks till next alarm
End Sub
Sub Globals
Dim btnTime, btnCancel As Button 'sets alarm, cancels alarm
Dim spnQuotes As Spinner
Dim p As Period :p.seconds = 30
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("page1")
initKVS.initalizingData
spnQuotes.AddAll(Array As String("Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6"))
End Sub
Sub Activity_Resume
alarmService.noti.Cancel(1)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnCancel_Click
StopService(alarmService)
CancelScheduledService(alarmService)
End Sub
Sub btnTime_Click
alarmTicks = DateTime.Now+(30*1000)
StartServiceAt(alarmService, alarmTicks, True)
ToastMessageShow("btn alarm set for " & DateTime.Time(alarmTicks),False)
End Sub
'if you change the quote then the alarm, via the service module, needs to be updated to reflect new notification text
'relies on the quote number, which uses the KVS
Sub spnQuotes_ItemClick (Position As Int, Value As Object)
'ToastMessageShow(Position, False)
initKVS.kvs.putsimple("quoteNumber", Position) 'this is used to display specific quote
If alarmTicks > 0 Then 'only run this if an alarm has been set
Do While alarmTicks < DateTime.Now 'make sure alarm is set in the future
alarmTicks = DateUtils.AddPeriod(alarmTicks, p)
Loop
StartServiceAt(alarmService,alarmTicks,True)
End If
ToastMessageShow("spn alarm set for " & DateTime.Time(alarmTicks),False)
End Sub
Service Module:
B4X:
Sub Process_Globals
Dim noti As Notification
Dim quoteNumber As Int 'save this in kvs
Dim quoteList As List
Dim quoteTitle As List
Dim AlarmTime As Long
End Sub
Sub Service_Create
quoteList.Initialize
quoteTitle.Initialize
Quotes
initKVS.initalizingData
quoteNumber = initKVS.kvs.GetSimple("quoteNumber")
End Sub
Sub Service_Start (StartingIntent As Intent)
noti.Initialize
noti.Light = False
noti.Vibrate = True
noti.OnGoingEvent = False
noti.Sound = True
noti.Icon = "icon"
noti.SetInfo(quoteTitle.Get(quoteNumber), quoteList.get(quoteNumber), Main)
noti.Notify(1)
Dim p As Period
p.seconds = 30
Do While AlarmTime < DateTime.Now 'make sure alarm is set in the future
AlarmTime = DateUtils.AddPeriod(AlarmTime, p)
Loop
StartServiceAt("",AlarmTime,True)
ToastMessageShow("service alarm set for " & DateTime.Time(AlarmTime),False)
End Sub
Sub Service_Destroy
noti.Cancel(1)
CancelScheduledService("")
End Sub
Sub Quotes
quoteList.Addall(Array As String("Quote 1", "Quote 2", "Quote 3", "Quote 4", "Quote 5", "Quote 6"))
quoteTitle.addAll(Array As String("Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6"))
End Sub
kvs module
B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
Dim kvs As KeyValueStore
End Sub
Sub initalizingData
If kvs.IsInitialized = False Then
kvs.Initialize(File.DirDefaultExternal, "mweData")
End If
If kvs.ContainsKey("quoteNumber")=False Then
kvs.PutSimple("quoteNumber", 1)
End If
End Sub