1

I'm wondering how to make an authentication screen (in this case with a 4-digit code) which would open every time the app is opened. I achieved this in a previous iOS project by showing a modal window from the AppDelegate, and I was wondering what the best way to go about doing this would be on Android. I can't seen to find info about this specific case anywhere.

Is there some kind of equivalent to the AppDelegate in Android? And how can I prevent users from just skipping the screen by clicking the android default back button?

Kurse
  • 23
  • 1
  • 4
  • Do you want to protect only your app by code of entive device? Answer depends on this. For your app only, simply override onResume method in your activity. – Northern Poet Sep 27 '17 at 07:57
  • Only the app. Would I need to do the override in every single activity of my app? – Kurse Sep 27 '17 at 08:14
  • Ah, that's clear now. You should do it in main (entry-level) activity. Or, if your app may start using many activities, use onActivityResumed of your application class. Here is a sample: https://stackoverflow.com/questions/28691986/application-level-onresume-android – Northern Poet Sep 27 '17 at 08:19
  • Heh, looks like your question is duplicate of my sample in previous comment. – Northern Poet Sep 27 '17 at 08:21
  • @Miller Yeah that should do, thanks a lot! I don't know how to +1 or mark comments as answers, but this is most likely it ^. – Kurse Sep 27 '17 at 08:40

2 Answers2

0

Two solutions comes to my mind:

  1. You can search for native solution - there is one: https://developer.android.com/reference/android/app/KeyguardManager.html method: createConfirmDeviceCredentialIntent But this is quite ugly and available with 21+ api

  2. You have to implement your own solution. To avoid clicking back button on device you have to override onBackPressed method in activity

Pyrkosz
  • 48
  • 9
  • Looks about good as far as the back button is concerned, but do you know how I can trigger the intent? – Kurse Sep 27 '17 at 08:12
  • 'KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); km.createConfirmDeviceCredentialIntent("exampleTitle", "exampleDexription");' This way you will ask for password used in phone settings. You can run this in onCreate or in onResume method. It depends of what you want to achieve. You can read about lifecycle here: https://developer.android.com/guide/components/activities/activity-lifecycle.html – Pyrkosz Sep 27 '17 at 08:22
0

Answered by @Miller

Ah, that's clear now. You should do it in main (entry-level) activity. Or, if your app may start using many activities, use onActivityResumed of your application class. Here is a sample: stackoverflow.com/questions/28691986/… – Miller

Kurse
  • 23
  • 1
  • 4