Hi all!
Here is what you need to auto start your app at boot up.
Create a service module and paste in the code below:
This service module will now auto start at boot up. if it finds a file 'autoStart.dat' in the 'File.DirInternal' folder it will activate the main activity and auto start your app.
Here is a helper function to create the file that will auto-start or not auto-start your app.
Have fun!!!
Here is what you need to auto start your app at boot up.
Create a service module and paste in the code below:
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.
Private tmrStart As Timer
End Sub
Sub Service_Create
'--- set timer to start app after 1 seconds
'--- this gives time for system to init other stuff
tmrStart.Initialize("tmrStart",1000)
End Sub
Sub Service_Start (StartingIntent As Intent)
'--- enabled timer
tmrStart.Enabled = True
End Sub
Private Sub Service_Destroy
End Sub
Sub tmrStart_Tick
tmrStart.Enabled = False
'--- if we find the file 'autoStart.dat' in the folder 'File.DirInternal'
'--- then auto start the app.
Dim checkFile As String = "autoStart.dat"
If File.Exists(File.DirInternal,checkFile) Then
Log("Auto Start is enabled")
StartActivity(Main)
Else
Log("Auto Start is disabled")
End If
End Sub
This service module will now auto start at boot up. if it finds a file 'autoStart.dat' in the 'File.DirInternal' folder it will activate the main activity and auto start your app.
Here is a helper function to create the file that will auto-start or not auto-start your app.
B4X:
Sub SetAutoStartAppOn(turnON As Boolean)
Dim checkFile As String = "autoStart.dat"
If turnON Then
If Not (File.Exists(File.DirInternal,checkFile)) Then
File.WriteString(File.DirInternal,checkFile,"on")
End If
Else
If File.Exists(File.DirInternal,checkFile) Then
File.Delete(File.DirInternal,checkFile)
End If
End If
End Sub
Public Sub GetAutoStartAppOn() As Boolean
Dim checkFile As String = "autoStart.dat"
If File.Exists(File.DirInternal,checkFile) Then
Return True
Else
Return False
End If
End Sub
Have fun!!!
Last edited: