Android Question #StartAtBoot: true doesn't work with android 9

mohamad.h.y

Member
Licensed User
hi first i Do apologize for my bad english i have a service in my app that has this code #StartAtBoot: true but in one phone with android 4... after reboot the phone service run automatically but this service doesn't work with another phone with android 9 anybody know BRIEFLY say to me which code i should write in my service that run after reboot on two android models this code doesn't work for me on android 9
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
the Notification indicate that the service is running

B4X:
#Region  Service Attributes
   #StartAtBoot: True  
#End Region

Sub Process_Globals
   Dim PhoneWakeState1 As PhoneWakeState
   Dim PhoneEvents1 As PhoneEvents
End Sub

Sub Service_Start(StartingIntent As Intent)
   
    Dim n As Notification
    n.Initialize
    n.Icon="icon"
    n.Sound=False
    n.Light = False
    n.Vibrate = False
    n.SetInfo("Alarm","Listening for a Alarm Message",Main)
    Service.StartForeground(1,n)

    PhoneWakeState1.PartialLock
   
    PhoneEvents1.Initialize("PhoneEvents1")
   
End Sub
 
Upvote 0

mohamad.h.y

Member
Licensed User
the Notification indicate that the service is running

B4X:
#Region  Service Attributes
   #StartAtBoot: True 
#End Region

Sub Process_Globals
   Dim PhoneWakeState1 As PhoneWakeState
   Dim PhoneEvents1 As PhoneEvents
End Sub

Sub Service_Start(StartingIntent As Intent)
  
    Dim n As Notification
    n.Initialize
    n.Icon="icon"
    n.Sound=False
    n.Light = False
    n.Vibrate = False
    n.SetInfo("Alarm","Listening for a Alarm Message",Main)
    Service.StartForeground(1,n)

    PhoneWakeState1.PartialLock
  
    PhoneEvents1.Initialize("PhoneEvents1")
  
End Sub

Hi doesn't work after reboot the phone
Android version : 9 PKQ1.180904.001
app is in release mode
 
Upvote 0

mohamad.h.y

Member
Licensed User
Ok,my phone is Redmi note 7 that has a Permissions-->Autostart section in settings
when you turn app on in this section app start automatically after boot
i wonder some apps (third party app no system app) in my phone are off in Autostart section but run automatically
after reboot (though this app has widget on desktop)
i am not familiar with widget programing
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
wonder some apps (third party app no system app) in my phone are off in Autostart section but run automatically
after reboot (though this app has widget on desktop)
It is not simple to know which apps are actually running. Why do you need to run your app on boot? It is not needed for push notifications.
 
Upvote 0
Top