Dear Sir,
I were looking for this question and I found nothing.I beg your pardon if exists an answer to my question.
I develop a application based on your GPS example. It has a Main and a GPS service (starter) As you know the service read GPS location and trigger Main subs.
IN the Main I have a SUB named SAVEGPS .It saves to SQL database the GPS labels (lblLat and lblLon) values.
On service I added a timer and each 30 seconds it tigger the MAIN SUB SAVEGPS
All works fine ... while the application its on front. When I hide application or when the smartphone "sleeps" after a while (screen is off) the service stops or the Main SUB SAVEGPS does not work because its on the Main module ( I am not sure what)
What I must do for it to work on background ? Maybe I must Place all SUBS en service module? (Starter)
Sorry for my English. I am not sure I explained well
Thanks in advance for your time and help.
Sub Service_Create
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.Vibrate=False
sNotif.SetInfo2("GPSPinger","Service Running","FromNotification",Main)
sNotif.Sound = False
sNotif.Notify(1)
Service.StartForeground(1,sNotif)
End Sub
This: Service.StartForeground(1,sNotif) will bring your service to run in foreground (which means it will run even if the app is brought to "background"). The notification is needed to inform the user that there is an app running in the background. Works for me (for several hours with screen switched off).
Please check your energy settings, too. On my Huawei I needed to switch on "can run in background" (settings -> apps -> your app -> energy -> can run when screen is off or similar)
I read about callSubDelayed and its said if activity is on background then the message will be stored in a special message queue. In this case the sub will be called when the target activity becomes visible. The sub will be called before Activity_Resume.
I think I have two choices :
a) Write down the SQL codes on service, not in Main
b) Call the activity .I mean "awake or show" the activity from BACKGROUND . But I do not know how to do this.