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

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 ?
 

Magma

Well-Known Member
Licensed User
@Erel ...actually this example... is my guide last days, the holy bible !!

Note that there are devices that will not allow your app to keep running in the background.
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 ?
 

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.
 

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...
B4X:
Sub Service_Destroy
   
If Tracking Then
        GPS.Stop
    End If
    Tracking = False
    lock.ReleasePartialLock

End Sub
Thanks in advance
 

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).
 

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...
 
Top