Android Question Password entry screen

gadgetmonster

Active Member
Licensed User
Longtime User
Hi All

I needed to create a password entry screen that could be called from any activity after a timeout. I did this by making a class called clsLockScreen. This class has a public method called LockScreen which goes something like this:

B4X:
Public Sub LockScreen

  DrawScreen

  Do while lbEnteredPassword.text <> setPassword

      DoEvents

  Loop

End Sub

So when called from an activity, the DrawScreen function will draw a panel over the entire screen and add a label and 10 numeric buttons. When the buttons are pressed, the number is added to lbEnteredPassword.text The loop will keep looping until such a time as the lbEnteredPassword label matches the set password.

Whilst this seems to work, I'm pretty sure this is not the right way to do it. Can anyone suggest a better method please?
 

stevel05

Expert
Licensed User
Longtime User
You shouldn't use a loop in this manner, you can consume the touch events from the panel by adding either empty Click and LongClick or Touch subs so nothing else can be processed and test and manage the password entry in the button up event.
 
Upvote 0

jsanchezc

Member
Licensed User
Longtime User
Yes, avoid Loops

Think about Dim a global variable at Main module
called UserLogged,
for example:
Dim UserLogged as Boolean=False

Then at _Resume of all activities check if UserLogged=true
if not, then call startactivity(activitylogin)

Here user can d login or exit app
If do login then set UserLogged=true and
all activities will work....

At Main activity you can put a Button to allow user Logout and set UserLogged=False or
end app
 
Upvote 0
Top