Android Question [SOLVED] ...after B4a updates.. problems with StartAtBoot and Long Running services...

Discussion in 'Android Questions' started by Magma, Apr 10, 2019.

  1. Magma

    Magma Well-Known Member Licensed User

    Hi there...

    I have b4a v9... well after some updates... i think after b4a v7+ - something changed - trying to figure what...

    I want my app starting automatically at boot and never stops for any reason - only when user kill proccess/service... not from android...

    Well i knew:
    - That is better not having in Starter - the official StartatBoot: True... so i have a service named Alarm
    - Better have different Service, and using:
    Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_NEVER
    and at Service_Start:
    Service.StartForeground(1, CreateNotification("..."))
    StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerMinute, True)

    But trying all the above with newer version of b4a and at 8.1 oreo.... and not starting automatically... and if it is sometimes killed by system!

    at Android 8.1 oreo at least at my phone there is option DURASPEED...(for working apps in background) if it is enabled at my app.. never killed...

    how can i bypass all these ... problems ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Check this example: Background location tracking

    Note that there are devices that will not allow your app to keep running in the background.
     
  3. Magma

    Magma Well-Known Member Licensed User

    @Erel ...actually this example... is my guide last days, the holy bible !!

    about the note: like the duraspeed thing... need to say users to change parameters...
    is there a tip for these devices ?

    how about the startatboot ? - my problem is that my app starts and after some minutes service killed... and the duraspeed is already enabled for my app... but if i ve started.. the service work ok (switch on at duraspeed)...

    + Searching the forum... somewhere see that now (after b4a v8+) i can use Starter safely with startatboot and backround services.... is it better or keep my service with different name ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You cannot use the starter service for this (and it wouldn't have matter). The best you can do is to have a foreground service. The OS is expected not to kill your app.
     
  5. Magma

    Magma Well-Known Member Licensed User

    and a last question... if my app need to run forever - is that needed ?

    i mean the code inside of sub...
    Code:
    Sub Service_Destroy
       
    If Tracking Then
            
    GPS.Stop
        
    End If
        Tracking = 
    False
        
    lock.ReleasePartialLock

    End Sub
    Thanks in advance
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    The service will not be destroyed if it is a foreground service so it doesn't really matter (and if the OS decides to kill your app then it will just kill it).
     
    DonManfred and Magma like this.
  7. Magma

    Magma Well-Known Member Licensed User

    For the story... when i totally DISABLE the DURASPEED option... the APP worked perfect... as a service... and startatboot... the only bad... is that i must say someway to users disable... but this is not only our problem but all developers have it... viber app too..

    So bad for all Developers... generally talking... must be something permission for startatboot.. from Google guys...
     
Loading...
  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