Android Question #StartAtBoot: True ...Doesn't work

studio4

Member
Licensed User
Longtime User
Hello, I need help. I have tried differents solutions but I haven't got any idea. I want that when my device power on, an service starts.

It is an example (In this case, I have tried open my app when my device power on), and when power on, appears .... "crashed".


--------SERVICE ------
#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)

StartActivity(Main)

End Sub

Sub Service_Destroy

End Sub

'-----END SERVICE

I have tried remove "StartActivity(Main)" in de "Service_Start" but, the application crashed too. It is to say, my app also crashed with the service is empty.

I need help, because I don't know that thing I am doing bad....
 

studio4

Member
Licensed User
Longtime User
When I compile with debug mode, doesn't appears any error because it happens only when I reboot my device, so I can´t obtain any logs after that. How can I obtain this logs?

In the other hand?... The error can be due to declare some variables in Process_Globals of the other activites? In same of theese activities I have declare variables which types are NotificationBuilder , list, HttpClient, HttpRequest, Object...

When I complile and open my app works perfectly. If I close my app and after that I open again, works perfectly too. The problem resides in the fact that I can't use a service module with startatboot. I need it for start anothers services which check some data bases of sqlite.

P.D: Sorry, my English isn't good.

Thanks, Erel.
 
Upvote 0

qsrtech

Active Member
Licensed User
Longtime User
It's been a while but i think i encountered this issue and resolved it by putting a timer in the service and start the activity in the timer tick. I use 10 seconds. Give it a try and see if that makes a difference.
 
Upvote 0

studio4

Member
Licensed User
Longtime User
RESOLVED


THANKSSSSSSS for your attention. I am very happy. I found the real problem...

The problem happens because I had declared some variables (of type: NotificationBuilder , list, HttpClient, HttpRequest) in "Process_Globals" of the several activities, but I had problems to detect it because the error doesn't say what was happening, only says (...chrased). The solution was: I have made a Class Module and I have declared all the variables there. Now, my service start when I power on my device perfectly but, at this moment I have to change a lot of things in my app after this changes.

Thank you a lot.
 
Upvote 0

freetoair

Member
Licensed User
Longtime User
When I try to:

#Region Service Attributes
#StartAtBoot: True
#End Region

I get this message:

B4A version: 5.02 (1)
Parsing code. Error
Error parsing program.
Error description: Attribute not supported: startatboot
Occurred on line: 16
#StartAtBoot: True

Why?
 
Upvote 0
Top