Android Question Starter service is not started before scheduled service

Pendrush

Well-Known Member
Licensed User
Longtime User
I have scheduled service (starts every day) and on some devices Starter service with image variable and KVS is not started before scheduled service. I get in crash log:
Object should first be initialized (Bitmap).

Starter service looks like:
B4X:
Sub Process_Globals 
   Public ImageOne As As Bitmap     
End Sub

Sub Service_Create
   ImageOne.LoadBitmap(File.DirAssets, "imageone.png")
End Sub

Scheduled service:
B4X:
Sub Service_Start (StartingIntent As Intent) 
   Dim notif As NotificationBuilder
   Dim NotifL As NotificationCustomLayout
   notif.Initialize
   NotifL.Initialize("laynotif")
   NotifL.SetTextField("Title", Application.LabelName)
   NotifL.SetTextField("Test", "xxx")
   NotifL.SetImage("AppIcon", Starter.ImageOne") '<- Error is triggered in this line
   notif.OnGoingEvent = True
   notif.DefaultSound = False
   notif.DefaultLight = False 
   notif.DefaultVibrate = False
   notif.AutoCancel = False
   notif.Priority = 2
   notif.ShowTime = False
   notif.Category = notif.CATEGORY_CALL
   notif.SmallIcon = "icona"
   notif.Visibility = notif.VISIBILITY_PUBLIC
   notif.CustomLayout = NotifL.BuildLayout
   notif.setActivity(actX)
   notif.Notify(1)
End Sub

Similar error is on other service with KVS declared and initialized in Starter service. Service witch use KVS also trigger error on the line:
B4X:
If Starter.Kvs.Get("xRange") = 1 Then
Error is:
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor anywheresoftware.b4a.sql.SQL.ExecQuery2(java.lang.String, java.lang.String[])' on a null object reference

Both errors are triggered in only about 0.5% of all devices. Sessions without crash: 99,5%.
Both app have combined over 70k active installations.
One more thing, both crashes looks like some kind of problem starting from latest B4A version.
This kind of crashes started to appear when apps get compiled with latest B4A v7.80.

EDIT:
I'm not able to reproduce this error on any of my devices and emulators, no matter what I try to do, but I can see error in Crash log (Firebase Analytics).
 

DonManfred

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Yes, all errors are on devices with API 24 (Android 7.0).
Some of devices from list: Moto C, Lenovo K53a48, LG-M250, Huawai VNS-L2, SLA-L02, Lenny4 Plus, etc.
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
srvSched is name of scheduled service.
I never schedule Starter service, as Starter start it self before srvSched in normal circumstances as it should.
App is tested and developed on devices with Android 7.0 and Android 7.1.2.

Other app have exact same problem as previous one but with KVS, as I write in first post.
App don't have scheduled service, but other services who is started from Main activity.
This code in service (not Starter) is somehow not initialized, but it is in Starter service.
B4X:
If Starter.Kvs.Get("xRange") = 1 Then
Error:
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor anywheresoftware.b4a.sql.SQL.ExecQuery2(java.lang.String, java.lang.String[])' on a null object reference
This service is started from Activity_Create.

As I stated in first post affected devices percent is about 0.5%, and not every time on that particular device, completely sporadic error, but will be nice to have proper solution.
As a workaround, before every call, I use .IsInitialized and reinitialize Bitmap or KVS again if it is False, something like:
B4X:
If Starter.Kvs.IsInitialized = False Then
    Starter.Kvs.Initialize(File.DirInternal, "setdb")
End If
If Starter.Kvs.Get("xRange") = 1 Then
'''''
End If
I still don't know is this proper solution. App will be updated to store in next couple days.
 
Upvote 0
Top