Adding a Service..

eps

Expert
Licensed User
Longtime User
Okay, so I've read all of the documentation and examples, but still can't seem to get this to work..

:sign0085:

I've got an existing App, which works fine and wanted to add a periodical check and Notify the phone user if the specified time had been reached.

So I added a Service module, using the B4A SDK. Then I placed a call to the service in my Activity.. I trimmed the code right down, but am obviously still missing something. Initially I had the Service StartService call in the Create Sub in the Activity, but then wondered if it was possible to call a Service there, as nothing else seems to do this.

So I now have :

Sub blahblah
StartService(FavouritesNotifier)
End Sub

which is called in :

Sub Activity_Create(FirstTime As Boolean)
<does lots of stuff, ListView, TabHost etc, including a Phone State check> and then :

blahblah

'AdMob call

End Sub

Here's the Service :

'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub
Sub Service_Create
do_stuff
End Sub

Sub Service_Start
'Service.StartForeground(1,n)
Dim n As Notification
n.Initialize
'n.Icon = "ic_stigdroid_small"
n.Icon = "icon"

'Dim Cursor3 As Cursor
'Cursor3 = SQL1.ExecQuery("SELECT name, startdate, display_date, event._id FROM event, favourite where event._id = favourite.fk_event_id order by date(startdate)")
'For i = 0 To Cursor3.RowCount - 1
' Cursor3.Position = i
' ListView3.AddTwoLines2(Cursor3.GetString("name"), Cursor3.GetString("display_date"), Cursor3.GetInt("_id"))
'Next
'Cursor3.Close

'If ShowToast = True Then
' ToastMessageShow("Single Click on items to see more information, Long Click on items to add them to Favourites",True)
'End If

n.SetInfo("&name&", "&display_date&", Main) 'Change Main to "" if this code is in the main module.
n.Notify(1)
End Sub

Sub Service_Destroy

End Sub
Sub do_stuff
Dim n As Notification
n.Initialize
'n.Icon = "ic_stigdroid_small"
n.Icon = "icon"

'Dim Cursor3 As Cursor
'Cursor3 = SQL1.ExecQuery("SELECT name, startdate, display_date, event._id FROM event, favourite where event._id = favourite.fk_event_id order by date(startdate)")
'For i = 0 To Cursor3.RowCount - 1
' Cursor3.Position = i
' ListView3.AddTwoLines2(Cursor3.GetString("name"), Cursor3.GetString("display_date"), Cursor3.GetInt("_id"))
'Next
'Cursor3.Close

'If ShowToast = True Then
' ToastMessageShow("Single Click on items to see more information, Long Click on items to add them to Favourites",True)
'End If

n.SetInfo("&name&", "&display_date&", Main) 'Change Main to "" if this code is in the main module.
n.Notify(1)
End Sub


:BangHead:

I'm guessing I haven't defined something - no extra Dims were created in the Activity when calling the Service..?? or is the Service just rubbish? I noticed StartServiceAt - do I need to call this, in order for the Service to start. I was expecting the Service to start and a Notify (effectively debug at this moment in time) to just appear.. but nothing does. The commented out code, will be adjusted and should create Notifications if a date (minus 1 or 2 days) is reached - from the DB. Any extra Libs to call?

:sign0163:
 

eps

Expert
Licensed User
Longtime User
The log says : Unable to start service Intent { cmp=torquesoft.themsc/.favouritesnotifier }: not found

I'll create a new Service and see if that works.. hmmm...
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Nope, new one...

Unable to start service Intent { cmp=torquesoft.themsc/.favouritesnotifying }: not found

???
 
Upvote 0
Top