Hi,
Manually move the process to trash, the service is also killed, but also the OS is killing it after longrun (deepsleepmode???)
I need to restart this service. Looking at processes like WhatsApp and Mail they seems to wakeup every time. I don't succeed in having a service running all the way.
My app is checking for messages from my server (and sending LatLon back every time).
I use the following code in a service not Starter:
Something like #StartCommandReturnValue: android.app.Service.START_STICKY is not supported anymore, but I need something simular, I think.
B4A v8.80 and Android 6.0 (and also 8.0.0)
I hope someone can help me making my service steady.
Best regards,
André
Manually move the process to trash, the service is also killed, but also the OS is killing it after longrun (deepsleepmode???)
I need to restart this service. Looking at processes like WhatsApp and Mail they seems to wakeup every time. I don't succeed in having a service running all the way.
My app is checking for messages from my server (and sending LatLon back every time).
I use the following code in a service not Starter:
B4X:
#Region Service Attributes
#StartAtBoot: True
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Interval As Int: Interval=2 'om de 2 minuten
Dim n As Notification
Private Check As Bitmap
Dim lock As PhoneWakeState
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
Check = LoadBitmapResize(File.DirAssets, "check.png", 24dip, 24dip, False)
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_WHEN_NEEDED
lock.PartialLock
End Sub
Sub Service_Start (StartingIntent As Intent)
Log("Done: "&DateTime.Time(DateTime.Now))
OphalenMessages
StartServiceAtExact(Me, DateTime.Now + Interval * DateTime.TicksPerMinute, True)
Service.StopAutomaticForeground
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub DisplayIcon (Body As String) As Notification
Dim notif As NB6
notif.Initialize("default", Application.LabelName, "HIGH").SmallIcon(Check)
notif.SetDefaults(False,True,True)
notif.AutoCancel(True)
n.Initialize
n=notif.Build("TEST", Body, "tag", Fingerprint)
Return n
End Sub
Sub OphalenMessages
<< MY CODE >>
if (newmessage=true) then
Service.StartForeground(1,DisplayIcon("New message..."))
End If
End Sub
Something like #StartCommandReturnValue: android.app.Service.START_STICKY is not supported anymore, but I need something simular, I think.
B4A v8.80 and Android 6.0 (and also 8.0.0)
I hope someone can help me making my service steady.
Best regards,
André