Say my app is running normally, showing Activity A. Then the user locks the phone. A dutifully goes to sleep (onPause()
). At some point while the screen is off, I need to show something to the user. So from my background code (service), I call startActivity for B, passing the following flags:
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_NEW_TASK
And in onCreate()
of B, I add the following window flags
FLAG_SHOW_WHEN_LOCKED
FLAG_TURN_SCREEN_ON
FLAG_DISMISS_KEYGUARD
That all works fine - B now appears on top of the keyguard.
At some later point, I wish to dismiss B, so from within B I call dismiss()
, which works out as expected. And here's where things go wrong:
Instead of returning to the lock screen, I now have A running on top of the lock screen.
How can I stop the OS from resuming A when I dismiss B?
Thanks.