I am running a service in the background which doesn't run on Android 7.0 when the phone goes to sleep mode. It runs fine on Android 6.0.1 in sleep. I thought services be definition ran in sleep but then I found the string on service.startforeground so I added it as shown in the code below. On A6.0 the service runs in sleep mode with or without service.startforegorund. On A7 it never runs in sleep mode.
B4X:
Sub Service_Create
Server.Initialize(19257, "Server")
Log("WIFIService Starting, MyIp = " & Server.GetMyIP)
serial1.Initialize("Serial1")
n1.Initialize
n1.Icon = "icon"
n1.AutoCancel = True
n1.Sound = False
n1.SetInfo("Wifi is listening","Click to stop",Stop)
Service.StartForeground(4, n1)
End Sub
Sub Service_Start(StartingIntent As Intent)
Server.Listen
Log("WIFI Service is Listening")
End Sub
I am running a service in the background which doesn't run on Android 7.0 when the phone goes to sleep mode. It runs fine on Android 6.0.1 in sleep. I thought services be definition ran in sleep but then I found the string on service.startforeground so I added it as shown in the code below. On A6.0 the service runs in sleep mode with or without service.startforegorund. On A7 it never runs in sleep mode.
B4X:
Sub Service_Create
Server.Initialize(19257, "Server")
Log("WIFIService Starting, MyIp = " & Server.GetMyIP)
serial1.Initialize("Serial1")
n1.Initialize
n1.Icon = "icon"
n1.AutoCancel = True
n1.Sound = False
n1.SetInfo("Wifi is listening","Click to stop",Stop)
Service.StartForeground(4, n1)
End Sub
Sub Service_Start(StartingIntent As Intent)
Server.Listen
Log("WIFI Service is Listening")
End Sub
On further testing it seems like the service is running but slowly. It seems to take much longer to reply to incoming requests. Is it possible that services in sleep mode run slower?
As the "sleep mode" is good for energy saving, this is a normal behaviour I think (as I know Android 7.x is optimized here). Take a search for PhoneWakeState and change the behaviour (your device then does not get into deep sleep).
As the "sleep mode" is good for energy saving, this is a normal behaviour I think (as I know Android 7.x is optimized here). Take a search for PhoneWakeState and change the behaviour (your device then does not get into deep sleep).
It looks like PhoneWakeState prevents the phone from going to sleep. I don't really want to prevent that. I just want the background service module to operate at normal speed in sleep mode and respond quickly to incoming requests by Server.Listen. Is there anyway to do that in And. 7x?
It looks like PhoneWakeState prevents the phone from going to sleep. I don't really want to prevent that. I just want the background service module to operate at normal speed in sleep mode and respond quickly to incoming requests by Server.Listen. Is there anyway to do that in And. 7x?