Android Question SOLVED - DEMO App provided - Log Off User when Device Goes to Sleep

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

I have seen a lot of threads related to the device sleep subject, but none seem to hit the mark for my purposes. My question is:

Would the following steps accomplish the task of logging off the user in my app when the device goes to sleep?

1. Device is going to sleep
2. I prevent it by PhoneWakeState.KeepAlive (I assume this goes in Act Pause.)
3. Log off user in my app
4. Release KeepAlive

Since I have no experience in this area, does anyone have a code snippet on this? I am certain that this requirement is not new.

Thank you in advance for your replies.

Sandy
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I tried the PhoneEvents (zero experience in this area and weak on Services)

This is the code (which must be wrong because it is not working):

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public PE As PhoneEvents
End Sub
Sub Service_Create
    PE.initialize("PE")
End Sub

Sub Service_Start (StartingIntent As Intent)
  
End Sub

Sub Service_Destroy

End Sub
Sub PE_ScreenOff
    CallSub(Main,"ResetMain") ' logs off user
  
End Sub

Any help will be appreciated.

Sandy
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
IT WORKS! Thanks, again, Erel.

I attach small demo project for those who want to apply this concept. See documentation for PhoneEvents for all events detected by the service.
 

Attachments

  • 3 Test ScreenOff.zip
    423.3 KB · Views: 160
Upvote 0
Top