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:
说我的应用程序正常运行,显示活动A.然后用户锁定电话。尽职尽责地睡觉(onPause())。在屏幕关闭的某个时刻,我需要向用户显示一些内容。所以从我的后台代码(服务),我为B调用startActivity,传递以下标志:
FLAG_ACTIVITY_CLEAR_TOP
FLAG_ACTIVITY_NEW_TASK
And in onCreate()
of B, I add the following window flags
在B的onCreate()中,我添加了以下窗口标志
FLAG_SHOW_WHEN_LOCKED
FLAG_TURN_SCREEN_ON
FLAG_DISMISS_KEYGUARD
That all works fine - B now appears on top of the keyguard.
一切正常 - B现在出现在键盘上方。
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.
在稍后的某个时刻,我希望解雇B,所以从B中我会调用dismiss(),这可以按预期运行。而且这里出现了问题:我现在已经在锁定屏幕上运行了A而不是返回到锁定屏幕。
How can I stop the OS from resuming A when I dismiss B?
当我解雇B时,如何阻止操作系统恢复A?
Thanks.
谢谢。
1 个解决方案
#1
0
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 e.g. the home screen on exit of Activity B, so that the lockscreen hopfully will get to the front.
如果我猜对了Android只是显示属于你的应用程序的Activity堆栈上的下一个Activity。我会尝试拨打另一个应用,例如活动B退出时的主屏幕,以便锁屏跳跃到前面。
You could also try to use the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
:
您还可以尝试使用标志FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:
If set, the new activity is not kept in the list of recently launched activities.
如果设置,则新活动不会保留在最近启动的活动列表中。
#1
0
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 e.g. the home screen on exit of Activity B, so that the lockscreen hopfully will get to the front.
如果我猜对了Android只是显示属于你的应用程序的Activity堆栈上的下一个Activity。我会尝试拨打另一个应用,例如活动B退出时的主屏幕,以便锁屏跳跃到前面。
You could also try to use the flag FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
:
您还可以尝试使用标志FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:
If set, the new activity is not kept in the list of recently launched activities.
如果设置,则新活动不会保留在最近启动的活动列表中。