You need the "phone" library and then use these examples.
B4X:
Dim ps As PhoneWakeState
ps.KeepAlive(True) '<-- Keeps the screen on at set brightness
ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again
Enjoy !!
EDIT:
I've just seen that you have done this and that it still sleeps after two minutes - it should not - but there must be a work around - I think the Os is detecting inactivity and forcing a closure - Anyone else with a work around ?
You need the "phone" library and then use these examples.
B4X:
Dim ps As PhoneWakeState
ps.KeepAlive(True) '<-- Keeps the screen on at set brightness
ps.ReleaseKeepAlive '<-- Releases the above command and allows the phone to sleep again
Sub Process_Globals
Dim pw As PhoneWakeState
End Sub
Sub Activity_Pause (UserClosed As Boolean)
pw.KeepAlive(True) 'set false if brightness is not needed
End Sub
Sub Activity_Resume
pw.ReleaseKeepAlive
End Sub
I don't own Xiaomi and can't test this, but there is possibility that Xiaomi just doesn't keep screen on, no matter what you do.
It completely depends what manufacturer decides to do and how they modify android.
I don't know if I am doing wrong with the following code but it works for me and make more sense .
B4X:
Sub Activity_Resume
pw.KeepAlive(True) 'set false if brightness is not needed
player1.Position = pos
player1.Play
End Sub
Sub Activity_Pause (UserClosed As Boolean)
pw.ReleaseKeepAlive
pos = player1.Position
player1.Pause
End Sub