Description: Prevent the phone from going to black energy saving screen
Select the Phone Library from the [Libs] tab in the IDE
Add the following in Sub Globals of the Activity you want to keep awake.
Put the Stay awake code in Sub Activity_Resume of the same Activity. For me I only need the Activity to stay awake if the user is taking a timed test.
Make sure you Turn Off the keep awake stake so you don't waste the battery. The place to do this in Sub Activity_Pause
Tags: Phone Library, PhoneWakeState, Android OS Function
Select the Phone Library from the [Libs] tab in the IDE
Add the following in Sub Globals of the Activity you want to keep awake.
B4X:
Sub Globals
Dim pw As PhoneWakeState
End Sub
Put the Stay awake code in Sub Activity_Resume of the same Activity. For me I only need the Activity to stay awake if the user is taking a timed test.
B4X:
Sub Activity_Resume
If (comp.gbTimer = True) Then
pw.KeepAlive(True)
End If
End Sub
Make sure you Turn Off the keep awake stake so you don't waste the battery. The place to do this in Sub Activity_Pause
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
pw.ReleaseKeepAlive
End If
End Sub
Tags: Phone Library, PhoneWakeState, Android OS Function
Last edited: