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

Discussion in 'Android Questions' started by studio4, Jul 19, 2015.

  1. studio4

    studio4 Member Licensed 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)


    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....
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the error message from the logs?

    Are you compiling your app in release mode?
  3. studio4

    studio4 Member Licensed 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.
  4. qsrtech

    qsrtech Active Member Licensed 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.
  5. studio4

    studio4 Member Licensed User


    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.
  6. freetoair

    freetoair Member Licensed 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

  7. sorex

    sorex Expert Licensed User

    did you put that in a service module or just in the main B4A file?
    DonManfred likes this.
  8. freetoair

    freetoair Member Licensed User

    just in the main B4A file !
  9. sorex

    sorex Expert Licensed User

    that only works for services

    Project > Add new module > Service module
    DonManfred likes this.
  10. freetoair

    freetoair Member Licensed User

    Ok sorex guessed the answer from your questions. It's all right, it works. thanks a lot
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice