How do I prevent screen timeout

FFMan

Member
Licensed User
Longtime User
I want to use my android device as a front end to another external system connected via bluetooth.

I can write the code no problem in b4a but being a newbie, i don't know how i can keep the android device awake. i can do this whilst on charge as there is a debug option in the application menu, but this doesn't help when on batteries.

Ideally i want to keep the screen on and keep all connections open until the user quits the app.

any help much appreciated.
 

ta1dr

Member
Licensed User
Longtime User
Hi Erel
I have same problems and I search forum and I read all thread but I didnt any sample could you write little sample code this about
thanks and regards
Ahmet
 
Upvote 0

Turbo3

Active Member
Licensed User
Longtime User
Two taps to shutdown when using ReleaseKeepAlive

I have tried this method but there is one side effect my users are seeing that I have verified.

With my app on screen if you tap the power button the screen turns off for a second or so and then comes back on to the lock screen. So you need to tap the power button twice to force off the screen.

If I comment out just the ReleaseKeepAlive in the Activity_Pause then tapping the power button turns off and keeps off the screen. But you need to exit my app to force a Release of the Keep Alive.

Seems that a tap of the power button does not allow enough time for the ReleaseKeepAlive to get processed by the system so it wakeup turning on the screen to finish processing. I see an Activity_Create (FirstTime=false) right have the Activity_Pause. I don't see Activity_Create if I comment out the ReleaseKeepAlive in Activity_Pause.

I have a Bluetooth Serial link active. Is that causing a problem? Do I need to suspend it some how?

Here is a log of activity for the good case (switch away from app then tap power and bad case tap power while app on screen)

B4X:
** Activity (main) Create, isFirst = false **
Activity_Create
Broadcast_Init
BroadcastReceiver has been initialized.
running waiting messages (1)
BtSerical_Connected
** Activity (main) Resume **
Activity_Resume
BtSerical_Connected

(At this point I used back key to switch away from app)

** Activity (main) Pause, UserClosed = true **
Activity_Pause

(Tap power button now and screen would turn off)
(Instead I switched back to app)

** Activity (main) Create, isFirst = false **
Activity_Create
Broadcast_Init
BroadcastReceiver has been initialized.
** Activity (main) Resume **
Activity_Resume

(Tap power button )

** Activity (main) Pause, UserClosed = false **
Activity_Pause

(Screen turned off but a second or so later it comes back on to lock screen)
(Note UserClosed=false)
(Why am I getting this Create?)
(Don't get it if I comment out ReleaseKeepAlive in Activity_Pause)

** Activity (main) Create, isFirst = false **
Activity_Create
Broadcast_Init
BroadcastReceiver has been initialized.
** Activity (main) Resume **
Activity_Resume
BtSerical_Connected

** Activity (main) Resume **

WakeLock already held.
Activity_Resume

(Second tap now the display turns off)

** Activity (main) Pause, UserClosed = false **
Activity_Pause
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…