Android Question [SOLVED]Error with Service

Stulish

Active Member
Licensed User
Longtime User
Hi All i am using some old code that worked and i cant see why it crashes now?
All i want is the kiosk service to start the main activity at boot up, the panel PC this is to be installed on allows you to hide the navigation bar and status bar at the top and bottom of the screen and also stop the swipt up/down to view them so as long as the app is running it is KIOSK.

The old code for the service is below:

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

'Service module
Sub Process_Globals
    Dim Notification As Notification
    Dim Timer1 As Timer
    Dim limitNumberOfTicks As Int
End Sub
Sub Service_Create
    If Notification.IsInitialized = False Then
        Notification.Initialize
        Notification.Icon = "icon"
        Notification.SetInfo("Kiosk app", "Kiosk app", Main)
        Notification.Sound = False
        Notification.Vibrate = False
    End If
    Timer1.Initialize("Timer1", 10)
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StartForeground(1, Notification)
    If IsPaused(Main) Then Timer1.Enabled = True
End Sub

Sub Service_Destroy
    Service.StopForeground(1)
    Timer1.Enabled = False
End Sub
Sub Timer1_Tick
    If IsPaused(Main) Then
        StartActivity(Main)
        limitNumberOfTicks = limitNumberOfTicks + 1
        If limitNumberOfTicks >= 10 Then Timer1.Enabled = False
    Else
        Timer1.Enabled = False
    End If
End Sub

The error i get at startup after i reboot the device is:

Logger connected to: rockchip rk3288
--------- beginning of main
** Receiver (kioskservice) OnReceive **
*** Service (kioskservice) Create ***
kioskservice_service_create (java line: 157)
java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
at anywheresoftware.b4a.objects.NotificationWrapper.getND(NotificationWrapper.java:92)
at anywheresoftware.b4a.objects.NotificationWrapper.setValue(NotificationWrapper.java:124)
at anywheresoftware.b4a.objects.NotificationWrapper.setSound(NotificationWrapper.java:109)
at lishsoft.SMIDS2.kioskservice._service_create(kioskservice.java:157)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at lishsoft.SMIDS2.kioskservice.onCreate(kioskservice.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3339)
at android.app.ActivityThread.-wrap4(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
--------- beginning of crash
java.lang.RuntimeException: Unable to create service lishsoft.SMIDS2.kioskservice: java.lang.RuntimeException: java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3349)
at android.app.ActivityThread.-wrap4(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:250)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at lishsoft.SMIDS2.kioskservice.onCreate(kioskservice.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3339)
... 8 more
Caused by: java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
at anywheresoftware.b4a.objects.NotificationWrapper.getND(NotificationWrapper.java:92)
at anywheresoftware.b4a.objects.NotificationWrapper.setValue(NotificationWrapper.java:124)
at anywheresoftware.b4a.objects.NotificationWrapper.setSound(NotificationWrapper.java:109)
at lishsoft.SMIDS2.kioskservice._service_create(kioskservice.java:157)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
... 11 more

any ideas would be greatly received.

Thanks

Stu
 

Stulish

Active Member
Licensed User
Longtime User
I think the error is at where you add SetInfo for the notification. It should be the last line after you set the other properties.
i.e after the line
B4X:
Notification.Vibrate = False

Thanks aeric, That works great, such a small thing šŸ‘ŒšŸ‘:)
 
Upvote 0
Top