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