Password Protection

XverhelstX

Well-Known Member
Licensed User
Longtime User
Heey everyone,

I have another question on locking your app with a password.

This is a code i use:

B4X:
Sub Activity_Resume

   Dim PasswordAsk As InputDialog
   Dim Passwordinput As String
            PasswordAsk.Input = PasswordAsk.INPUT_TYPE_TEXT
            PasswordAsk.PasswordMode = True
            PasswordAsk.Hint = "<1234>"
            PasswordAsk.HintColor = Colors.ARGB(196, 255, 140, 0)
            ret1 = PasswordAsk.Show("Enter your password below.", "Password", "Ok", "","", Trackedbmp)
            Passwordinput = PasswordAsk.Input
            If ret1 = -1 Then
               If Passwordinput = Interceptor.PasswordString Then
               Return True
               Else
               Activity.Finish()
               End If
            End If
   CallSub("","Activity_KeyPress (KeyCode As Int) As Boolean")

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean

If Keycode = KeyCodes.KEYCODE_BACK AND canFinish = True Then
   canFinish = False
    activity.Finish()
   
End If


End Sub

but now, when you press the back key, the dialog just close. I want to know that when you press the back key, the activity closes instead of the dialog.

How should I do this?

XverhelstX
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
hmm weird, I have managed to fix it with a simple code.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean

If Keycode = KeyCodes.KEYCODE_BACK AND canFinish = True Then
   canFinish = False
    activity.Finish()
   
End If


End Sub

Sub Activity_Resume
   canFinish = True
   
   If StopMainActivity = "StopActivity" Then
   StopMainActivity = ""
   activity.Finish()
   End If
   Dim PasswordAsk As InputDialog
   Dim Passwordinput As String
            PasswordAsk.Input = PasswordAsk.INPUT_TYPE_TEXT
            PasswordAsk.PasswordMode = True
            PasswordAsk.Hint = "<1234>"
            PasswordAsk.HintColor = Colors.ARGB(196, 255, 140, 0)
            ret1 = PasswordAsk.Show("Enter your password below.", "Password", "Ok", "Cancel","", Trackedbmp)
            Passwordinput = PasswordAsk.Input
            If ret1 = -1 Then
               If Passwordinput = Interceptor.PasswordString Then
               Return True
               Else
               Activity.Finish()
               End If
            Else
               Activity.Finish()
            End If
   CallSub("","Activity_KeyPress (KeyCode As Int) As Boolean")

End Sub
 
Upvote 0
Top