开发者

How to password protect an application in Android

I want the user to enter a password everytime he tries to enter the application. That is, the user must enter the password everytime the app comes to foreground from background, be it by pressing the launcher icon or long-pressing the home key

I sort-of achieved the first par开发者_如何学Ct because the launcher intent is fired and i get a callback in onRestart of that activity.

But by long-pressing home key and launching the does not provide callback to onRestart.

Also what if the user launches the app by pressing the notification from, the notification bar. How do I distinguish whether the app was originally in background or fore-ground before the user clicked the notification


In your onResume call, set a loginCounter += 1, in your onPause -= 1.

if loginCounter == 0 => show Login Dialog.

In the Notification Bar you set an Intent to call the Activity, correct? Simply add a parameter "isCalledByNotificationBar" as boolean in there.


If onResume doesn't work, how about onWindowFocusChanged(boolean)?


Perhaps what you should do is on re-entry into the application see if it's been less than 30 (?) seconds since a timestamp that you update when any activity of your application was last paused. If it's been less, don't ask for a password. Thinking being that this short time window might smooth over some transitions you don't want to log out on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜