简体   繁体   中英

Activity on lockscreen - dismissing it resumes previous activity

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 BI 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.

If I guess right than Android just shows the next Activity on the Activity stack belonging to your app. I would try to call another App eg the home screen on exit of Activity B, so that the lockscreen hopfully will get to the front.

You could also try to use the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS :

If set, the new activity is not kept in the list of recently launched activities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM