The question is not related to B4XPages and you shouldn't access B4XPages from the service. B4XPages will only be available after the main activity has started.
Make sure to run your app in release mode and make sure to check the logs.
Hi
@Erel
first of all, happy Sunday.
Sorry for make this post a little long but this feature is important about the project that I'm developing for my customer.
I tested this service code with Android 7, Android 8, Android 9 and Android 10 (AVD devices):
#Region Service Attributes
#StartAtBoot: true
#End Region
Sub Process_Globals
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
'Service schedule
Private NumOfSeconds As Int = 30 '1 hour = 3600 secs
StartServiceAt(Me, DateTime.Now + NumOfSeconds * DateTime.TicksPerSecond, True)
Private smiley As Bitmap = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
Simple_Notification ("BotegApp NEWS", "Ci sono delle novità per te! Scopri quali...", "new_art", smiley)
End Sub
Sub Simple_Notification (aTitle As String, aContent As String, aTag As String, aSmallIcon As Bitmap)
Dim n As NB6
n.Initialize("default", Application.LabelName, "HIGH").AutoCancel(True).SmallIcon(aSmallIcon)
n.Build(aTitle, aContent, aTag, Main).Notify(4) 'It will be Main (or any other activity) instead of Me if called from a service.
End Sub
Sub Service_Destroy
End Sub
I tested it in this way :
Note: all test are done in release mode.
1) I installed the app on all 4 AVD devices and run one
2) I shutted down all the AVD devices
3) I power on al the 4 AVD devices
RESULT
- The service is started at boot on all 4 devices (Android 7, 8, 9 and 10).
- The service is still running scheduled each 30" showing the notification on all Android versions (from 7 to 10).
So this is a success (so in this case I can say: "all work fine on all the tested Android versions), but ... this is true only within virtual devices with "pure" Android (not customized android).
THE PROBLEM
If I install the same app within my real device, a "Xiaomi Redmi Note 8 Pro" (with Android 10) and I did the same test (as above), the service doesn't start.
For me this is a insidious problem because people use real devices (not virtual google devices) and I have to "certify" this feature as "working feature" in front of my customer (the company that commissioned me the app).
So my questions are:
1) How to solve / handle this (I need to tell to my customer on which Android versions is tested and "certify" the app) ?
2) How can I known if only on this (real) Android 10 device the #StartAtBoot doesn't work ?
Thanks in advance for your precious help.
Luca.