0

I have an android app and for security reasons it can never be left on while a user is not using it. How can I restart my app when the user locks the screen or it auto locks.

When the user unlocks the device is should be at the login activity.

Can I clear all tasks when the screen is locked. How is this done?

Update

I cannot finish() activities in the onPause as i use onPause for NFC foregroundDispatch so i need a different solution

Rob85
  • 1,719
  • 1
  • 23
  • 46
  • 1
    On Pause override is what will be triggered when the app is not visible – ΦXocę 웃 Пepeúpa ツ Jun 24 '16 at 21:13
  • 1
    is OnPause called for other reasons because if i finish the activity and it is called else where then that would cause issues – Rob85 Jun 24 '16 at 21:16
  • ok so far that works nicely, i didn't realise you could have multiple activities be finished at the same time in this way, i am just reading the document on when onPause is called. – Rob85 Jun 24 '16 at 21:25
  • it does cause issue as i use onPause and onResume for NFC, i would need a different solution – Rob85 Jun 24 '16 at 21:27

1 Answers1

1

You would need to create a broadcast receiver that listens for the broadcast action ACTION_SCREEN_OFF and set a state in your session to help your app to decide when the onResume calls start. (see link). Here is a link with someone asking how to implement this receiver (see link)

Community
  • 1
  • 1
daniel.brubeck
  • 644
  • 4
  • 10