Putting android to sleep

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I have been trying to put android asleep grammatically.

I have tried:

B4X:
Dim p As Phone, n As Float = 0
p.SetScreenBrightness(n)

This does seem to work but my app has problems restarting after this. Is there another way to do this?
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
If I put the app asleep with the power button or wait for the android to put it asleep all is well, When I press the power button or a timer fires my app comes back fine.

If I use the code above to put it asleep.
The 1st time I press the power button nothing happens.
2nd time the screen powers up but displays nothing.
3rd time it goes blank again.
4th time most of my app comes back but some of the screen is not displayed.

Has to be something different between me putting it asleep and the system doing it.
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
0.1 just dims the screen and when I press the power button it goes to sleep.

I am going to create a small project, pull out the code and see if I can reproduce it in a small program.

I did notice one other thing. When I press the power button to try and wake it up the 'Activity_Pause' keeps firing, I think thats why my app is having problems waking up.
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Here is a small sample that shows the problem.
Fails on both my phone and tablet.


Be careful with this program, it can lock you device up so that it needs to be re-started
 

Attachments

  • androidSleepProblem.zip
    6.6 KB · Views: 222
Last edited:
Upvote 0
Top