This is a part of my Code Snippets collection, needed in many projects.
Sometimes you don't want the display to turn off, even if there is no user action for a while. Handling this is possible for Android and iOS, but in different ways. That's why the OS specific class is the best place for this method. See B4i solution here.
Sometimes you don't want the display to turn off, even if there is no user action for a while. Handling this is possible for Android and iOS, but in different ways. That's why the OS specific class is the best place for this method. See B4i solution here.
in an OS specific class (not parent folder):
Sub Class_Globals
Private wkup As PhoneWakeState 'Phone' Lib
End Sub
Sub KeepScreenAlive(active As Boolean)
If active Then
wkup.KeepAlive(True)
Else
wkup.ReleaseKeepAlive
End If
End Sub
In an Form/B4XPage, that you want to prevent from turning off the display:
Sub B4XPage_Appear
Main.cG.OSSpec.KeepScreenAlive(True)
End Sub
Sub B4XPage_Disappear
Main.cG.OSSpec.KeepScreenAlive(False)
End Sub
Last edited: