Android Question Service.StartForeground ID value

Michael Gasperi

Member
Licensed User
Longtime User
I've only seen examples of Service.StartForeground where the ID = 1. For example: Service.StartForeground(1,test). Is there something special about the 1? I own a tablet where I have to make the ID = 0 or it will error on the call.
 

DonManfred

Expert
Licensed User
Longtime User
I dont know id the 0 is allowed as an ID for the notification object (see docu of this object and the ID)
But if it is allowed then you can use a 0 too if you use the 0 in the definition of the notification object
 
Upvote 0

Michael Gasperi

Member
Licensed User
Longtime User
Setting ID to 0 makes the Service.StartForeground just do nothing. What I'm finding is that I need to NOT set the Icon property for the call to work. I suspect this indicates some stupidity on my part. Any idea what I'm leaving out here?

Below is the service routine whose sole function is to keep the app from being killed. Every second it updates a clock in the activity.


B4X:
Sub Process_Globals
    Dim Notification1 As Notification
    Dim timer1 As Timer
End Sub
Sub Service_Create
    Notification1.Initialize
    'Notification1.Icon = "icon"
    Service.StartForeground(1,Notification1)
    timer1.Initialize("timer1",1000)
    timer1.Enabled = True
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
    timer1.Enabled = False
End Sub

Sub timer1_tick
    CallSub(Main, "Clock")
End Sub
 
Upvote 0

Michael Gasperi

Member
Licensed User
Longtime User
I was trying to do what you told me in this thread: https://www.b4x.com/android/forum/threads/really-keeping-an-app-alive.53770/#post-337049

Basically I want an app that keeps a display of some current information 24/7. I've tried putting a KeepAlive(True) in Activity_Resume, but once and a while I find that the phone/tablet is just sitting on the home page like the app had been killed. The solution was supposed to be a Service.StartForeground, but I'm not having luck getting that call to work.
 
Upvote 0
Top