Android Question Wake State with Screen Timeout and Different Activity

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hi All.

I'm having some issues with the implementation of WakeState.

In my Activities, I have implemented:

B4X:
Sub Activity_Resume
    WakeState.KeepAlive(False)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    WakeState.ReleaseKeepAlive
End Sub

In my Device, I have the follow configuration:

Configuration -> Display -> Screen Time Out -> 30 seconds

My App receives a GCM notifications.

So after some minutes (really all scenarios after 30 seconds), when the related activity that process the message starts, the display turn off, and after 1 or 2 seconds turn on automatically. This happens in Samsung Mini 3.

But when I'm testing my App in a Motorola RAZR HD, the Display just turn off.

Anybody have any ideia in how to solve this issue?

Thanks.
 

Eric H

Active Member
Licensed User
Longtime User
Which behavior is desired? You describe 2 behaviors but don't indicate which one is desired. Please clarify your question specifying what you expect to happen vs what is happening that is not desired.

Eric H
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
does this code work for you? replace layout with a layout of your own:

B4X:
Sub Globals
    Dim stayawake As PhoneWakeState
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("whatever")
    stayawake.KeepAlive(True)
End Sub

Sub Activity_Resume
    stayawake.KeepAlive(True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    stayawake.ReleaseKeepAlive
End Sub
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Eric H, sorry my delay. I'm reproducing all the scenario is a little complex. I will finish the implementation today later.

I'm using a GCM implementation, and when I receive a new message a new activity is started. In this moment (only if the message arrived after the screen time out) I have the display turns off.

So I have here little particularity. I have a new activity starting just after receiving a message by GCM.

If you have any other idea, it will be great to listen you.
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
recommendation is to test the wakestate in the simplest way possible, independently of your specific implementation to see if the problem is because your phone doesn't respond to wakestate properly or if the problem is caused by some other part of your code that isn't working the way you intend it to. The example code I posted was to help you answer that question. One you know that answer, that will tell you if the problem can be fixed by changing the code in your implementation, or if there isn't anything you can do about it because your device isn't capable of responding to a wakestate request. Does this make sense?

Regards,
Eric H

Edit:

Sorry I didn't see your earlier response:
I tried the suggested code, but the behavior is the same. Any other suggestion?

In this case, I don't have any other suggestions other than just googling Android wakestate and your device name to see if any other people have noticed the same issue. Also, are you using the newest version of Basic4Android and the most up to date Basic4Android library versions?

Best of luck,
Eric H
 
Last edited:
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Sure Eric H. The interesting of that is that behaviour occurs in all devices I tested. And these occurs in Samsung Mini, and two different motorola, with different Android versions. So probably the main point is my code.

I tried the simple implementation you suggest and works fine without any problem. The screen just turn off, when I have the implementation using the code of receiving a message from GCM and Start a new Activity.
 
Upvote 0

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Eric H, just to let you know.

I tried the code you suggest. It works like a charm. So I take all my attention to my code, I now I trying some fix, like remove the ReleaseKeepAlive, of the new activities.

This method it's now only called in the main activity. Apparently is working now. Thanks for you help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…