Android Question service module

Isac

Active Member
Licensed User
Longtime User
Hello,

I have a problem with the service module: If I turn off and then I turn on the phone the alarm does not work.

I tried to use: # StartAtBoot: True

But as soon as I turn on the phone immediately starts the service module, but this is not good.

thanks
 
Last edited:
You run into the same problem like the one in this thread. See the comments there and you´ll have a solution for your problem ;)
 
Upvote 0
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

Code: Copy
#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
 
Upvote 0
Erel I created the new service module, now how do I share the given variable of the module Main?


Code: Copy
 #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
 
Upvote 0
Hi,
To retrieve Process_Globals you have to reference it by the module's name and the variable name.
For example : Main.Variable_Name

Of course, Variable_Name should not be Private

Tip: Sometimes it is easier to store the content of the variable in a file and retrieve it from the running service. Just an idea in case of.
 
Upvote 0
thanks

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)

Code: Copy
 #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
 
Upvote 0
Excuse, this is not the correct usage.

In the Main activitiy

Code: Copy
Sub Process_Globals
  Dim Date1 as Long
End Sub

And in the Service module you make the reference to the Main.date1


Code: Copy
#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
 
Upvote 0
Thanks lemonisdead,

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)

Code: Copy
#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)

Code: Copy
#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

this is a piece of code Main

Code: Copy
date=DateTime.Add(DATA,0,0,Giorni)

StartServiceAt(boot,date,False)


I do not understand why the service module boot starts without waiting for the date.
 
Upvote 0
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...
 
Upvote 0
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.
 
Upvote 0
Hi Lemonisdead,

I could use the TextWriter to save the date of a txt file?
and then recall it with TextReader?

thanks
 
Upvote 0
I am using the class Keyvaluestore:
But I need your help because it does not work.

This main module
Code: Copy
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
Code: Copy
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("")

Starsts module is OK
 
Last edited:
Upvote 0
In compiling no errors but when I turn off and turn on the phone comes out a message saying that the application will be blocked.
 
Upvote 0
Back
Top