Android Question [CLOSED] SetShowWhenLocked and screen closed manually

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

I am referring to the code that Erel had kindly provided to unlock the screen when the app is visible. I have noticed that when the user has pressed the power button and shut down the screen, the code won't work again till the user has powered on the screen again.

I already have tried to clear the flags when the screen is off and run again the SetShowWhenLocked but with no success. I have tried to close the activity when the screen is off and relaunch it from a service when it is on again but with no more success.

Please, do you have any idea how to handle this and be sure the SetShowWhenLocked really unlocks the screen each time ? Many thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello Erel, I do thank you a lot for your reply and the interest to my question. Perhaps don't I use the function correctly.

I have attached a sample project. It is a Main activity in charge of starting a service which starts and closes a second activity (A2).
All is working fine if I let the service do its job alone. But till the user presses the power button to close the screen, I can't see A2 over the screen.

I have tried to comment the code and hope the comments to be clear enough. Thanks again, Erel
 

Attachments

  • test_SetShowWhenLocked.zip
    10.4 KB · Views: 357
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Edit: I mean : "when the user powers the screen off while A2 is shown"
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
About the unlock the lock screen, Yes, I have taken this in count whith using the SetShowWhenLock function you have kindly provided.
About the CallSubDelayed, when the screen is manually set to off, the activity is Paused with Userclosed (False) but is still visible.

And in the "normal operation mode" (when the service is handling the opening/closing of the A2 activity, all is fine : A2 opens, the screen light is on and off without problem.

What I have noticed too, is the A2 - Resume called twice and the state of UserClosed is set to True when s1 handles the closing and False when the screen was set to off manually.

1st
** Activity (main) Resume **
** Service (s1) Create **
** Service (s1) Start **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Pause, UserClosed = false **
** Activity (a2) Create, isFirst = true **
** Activity (a2) Resume **
** Activity (a2) Resume **
** Activity (a2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

Normal open/close operation (screen is not put off by the user
** Activity (a2) Create, isFirst = false **
** Activity (a2) Resume **
** Activity (a2) Resume **
** Activity (a2) Pause, UserClosed = false **
** Activity (a2) Resume **
** Activity (a2) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **

Operation when the screen was set to off by the user when A2 was shown
** Activity (a2) Create, isFirst = false **
** Activity (a2) Resume **
** Activity (a2) Resume **
** Activity (a2) Pause, UserClosed = false **

So I have tried to put a call to the Hide sub (A2) from Activity_Pause in A2 when UserClosed is False but this won't work.

What I am trying to do is to be sure that A2 will pop-up each time when s1 calls A2. Any idea ?
 

Attachments

  • test_SetShowWhenLocked.zip
    10.4 KB · Views: 335
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hi Erel,

Despite my trials it still won't work. Sorry. Using the StateManager does light thé screen but the activity is still behind the lockscreen if the user closed it manually.

Any other idea ? Tanks again
 
Upvote 0

Sgardy

Member
Licensed User
Longtime User
I used to use this code:
SetShowWhenLocked:
Sub SetShowWhenLocked
    r.Target = r.GetActivity
    r.Target = r.RunMethod("getWindow")
    r.RunMethod2("addFlags", 6815872, "java.lang.int")
End Sub

It works fine but fails in some phone, then I changed with this:

SetShowWhenLocked:
Sub SetShowWhenLocked

    Dim jo As JavaObject

    jo.InitializeContext

    Dim window As JavaObject = jo.RunMethod("getWindow", Null)

    window.RunMethod("addFlags", Array(524288))

End Sub

But if I switch the screen off it doesn't turn on again, so I used the same value of the older version and It works fine now:

SetShowWhenLocked:
Sub SetShowWhenLocked
    Dim jo As JavaObject
    jo.InitializeContext
    Dim window As JavaObject = jo.RunMethod("getWindow", Null)
    window.RunMethod("addFlags", Array(6815872)) '524288
End Sub
 
Upvote 0
Top