[英]How can I launch an activity to be on top of all other activities?
I am trying to create an application that defines two activites. 我正在尝试创建一个定义两个活动的应用程序。 The first activity pretty much runs all of the time. 第一个活动几乎一直都在运行。 The second activity requires the user to authenticate to use the device. 第二项活动要求用户进行身份验证才能使用设备。
Most of the time this application works fine. 大多数情况下,此应用程序运行良好。 However, I am having problems figuring out how to force the second activity to the top of the window stack. 但是,我在弄清楚如何将第二个活动强制到窗口堆栈顶部时遇到问题。 The code calls startActivity passing in an intent to start the second activity. 该代码调用startActivity传入一个意图以启动第二个活动。 The problem is that when another application is running (eg a web browser), the second activity is not on top. 问题在于,当另一个应用程序正在运行时(例如,Web浏览器),第二个活动不在最上面。 When the other application exits, the second activity is visible to take input from the user. 当其他应用程序退出时,第二个活动可见,以接受用户的输入。
Here is the activity definition for the second activity that I want to have always on top when started: 这是第二个活动的活动定义,我希望在开始时总是将其放在最前面:
<activity android:name=".Authenticate"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden">
</activity>
It is my understanding that when start activity is called, it will put the new activity on top. 据我了解,当调用start活动时,它将把新活动放在首位。 Is there something that I am missing? 有什么我想念的吗? How can I make the authentication activity come to the top when it is started? 启动身份验证活动时该如何使其达到最高?
Well AFAIK, you cannot force your Activity to stay on top all the time. AFAIK,您不能强迫您的活动始终保持领先。 If some other process (say Web Browser) creates an Activity after you have created yours, then that processes Activity will have focus and not yours. 如果在创建活动之后,其他某个进程(例如Web浏览器)创建了活动,则该活动将具有焦点而不是您的焦点。
每当一个新的活动开始时,它就位于堆栈的顶部,并且如果另一个应用程序正在运行,则它将位于堆栈的顶部,如果您希望活动位于堆栈的顶部,则应该停止启动其他应用程序...是否有我想念的东西,然后让我知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.