Erel how can I change the service module?
I have no idea, now when I turn on the phone sevice module starts by itself.
thanks
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim n As Notification
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
n.Initialize
n.Icon = "icon"
n.SetInfo("warning ", "You have reached the date","")
n.Notify(1)
End If
End Sub
Sub Service_Destroy
StopService("") 'Stop this service
CancelScheduledService("") 'Cancel this service
End Sub
Create another service and set the second service to start at boot. You can then call StartServiceAt from the second service to schedule the first one.
Erel I created the new service module, now how do I share the given variable of the module Main?
B4X:
#Region Service Attributes
#StartAtBoot: true
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt(start,date,False)
End Sub
Sub Service_Destroy
I tried to insert Main.date, but the variable does not see it.
Parsing code. Error
Error parsing program.
Error description: Undeclared variable 'date' is used before it was assigned any value.
Occurred on line: 19
StartServiceAt(start,date,False)
B4X:
#Region Service Attributes
#StartAtBoot: true
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Main.date
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt(start,date,False)
End Sub
Sub Service_Destroy
End Sub
And in the Service module you make the reference to the Main.date1
B4X:
#Region Service Attributes
#StartAtBoot: true
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.'These variables can be accessed from all modules.
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent AsIntent)
StartServiceAt(start,Main.date1,False)
StopService("")
End Sub
Sub Service_Destroy
End Sub
That's fine but when I restart the phone the service module will start automatically without waiting for launch date.
this is the first service module called (boot)
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt(start,Main.date,False)
StopService("")
End Sub
Sub Service_Destroy
End Sub
This is the second service module called (start)
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim n As Notification
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
n.Initialize
n.Icon = "icon"
n.SetInfo("warning ", "You have reached the date","")
n.Notify(1)
End Sub
Sub Service_Destroy
StopService("") 'Stop this service
CancelScheduledService("") 'Cancel this service
End Sub
On device reboot the date you set is lost... Save the date when setting the servicestartat to somewhere... Key value store, db, statemanger, whatever.. On service start at boot you check whether the desired date is reached or not. If not then set the new startat and quit. If the date is reached or in ast then do the work.
Search the forum. There was a few threads handling this issue...
Hi Isac,
You can use several methods. You could take a look at the File keyword. For example, you can save a list or a map with the useful information.
I am using the class Keyvaluestore:
But I need your help because it does not work.
This main module
B4X:
dim memoria as Keyvaluestore
date=DateTime.Add(DATA,0,0,Giorni)
memoria.Initialize(File.DirDefaultExternal,"datastore")
memoria.PutSimple("date",date)
StartServiceAt(boot,date,False)
This module boot
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
dim memoria as Keyvaluestore
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
memoria.Initialize(File.DirDefaultExternal,"datastore")
DateTime.date(memoria.GetSimple("date"))
StartServiceAt(starts,"date",False)
StopService("")