Service StartForeground Questions

GuyBooth

Active Member
Licensed User
Longtime User
I am trying to make my music player service run in the foreground using Startforeground. So far I have no indication that I have succeeded, since I don't see any notification. Questions I have:
Where should the Service.Startforeground statement be included - in the Service module "Service_Create"? Or the Service module "Service_Start"?

My code looks like this:
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim bPausedByPhone As Boolean
   Dim MPP As MediaPlayer
   Dim lstTracks As List
    Dim PE As PhoneEvents
   Dim PhoneNumber As PhoneId   
   Dim nNotify As Notification   
End Sub
Sub Service_Create
   MPP.Initialize2("MPP")
   lstTracks.Initialize
    PE.InitializeWithPhoneState("PE", PhoneNumber)
    nNotify.Initialize
   nNotify.Icon = "icon.png"
   nNotify.SetInfo("Music Player", "Tap to open player.", TMM_Run) 
   nNotify.Sound=False
   nNotify.Vibrate=False
   nNotify.Light=False
   nNotify.OnGoingEvent=True
   Service.StartForeground(1,nNotify)
End Sub
Sub Service_Start (StartingIntent As Intent)
   ' Start the Player

End Sub
The Icon is a png icon that is displays fine for the application in the device applications menu. It's located in the objects/res/drawable folder. The service is started from a running activity and is certainly running.
Any help appreciated :)
 
Top