Android Question Is this 'bad practice'

gz7tnn

Member
Licensed User
Longtime User
I have an sms app underway that uses a service. Without going into detail, my preference is to have the service always running, but it does sometimes get killed. I can live with that but have looked at alternates to keep it alive and have tried (successfully) the following approach.
Using the Phone library I now also start the service when a phone call is either received or made, as well as the desired method of when an sms message is received.

The thought here is that it now gives the app three different intents to listen for that would restart the service if it fails.
While maybe not the ideal situation I wonder what the general feeling is on this approach. Is it 'acceptable' or 'totally bad' practice.
 

gz7tnn

Member
Licensed User
Longtime User

Hi Erel
I have seen that one and did already have service.startforeground in my code, but it still seems to stop occasionally.
I have added the start_sticky and will see how that goes.
I now have the following in my service module. (have removed other non related lines in this sample).
Is the following code look correct?

#Region Service Attributes
#StartAtBoot: true
#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region

'Service module
Sub Process_Globals
Dim SI As SmsInterceptor
Dim sNotif As Notification
End Sub

Sub Service_Create
SI.Initialize2("SI", 999999)
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("MyApp","Service Running",Main)
sNotif.Sound = False
sNotif.Notify(1)

Service.StartForeground(1,sNotif)

End Sub
 
Upvote 0
Top