How to password protect an Android app

I want the user to enter a password every time he tries to enter the application. That is, the user must enter the password each time the application comes to the forefront from the background, for example, by clicking the start icon or by pressing the main key

I sorted the first part because the intent of the launch was starting, and I get a callback in onRestart of this action.

But with a long press of the master key and starting, the onRestart callback is not provided.

Also, if the user launches the application by clicking the notification , the notification panel. How can I tell if the application was originally in the background or before the user clicked a notification

+3
source share
3 answers

In your call, onResumeset loginCounter+ = 1 to onPause- = 1.

if loginCounter == 0 => show the login dialog.

In the notification panel, you set Intentto call Activity, right? Just add the parameter "isCalledByNotificationBar" as Boolean.

+1
source

If it onResumedoesn’t work, how about onWindowFocusChanged(boolean)?

+1
source

, , , 30 (?), , , - . , . , , .

+1
source

Source: https://habr.com/ru/post/1777886/


All Articles