Android Question Service.StartForeground ID value

Michael Gasperi

Member
Licensed 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.
 

Michael Gasperi

Member
Licensed 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
 

Michael Gasperi

Member
Licensed User
I was trying to do what you told me in this thread: http://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.
 
Top