我如何才能启动一项活动以使其优先于所有其他活动?
我正在尝试创建一个定义两个活动的应用程序。第一个活动几乎一直在运行。第二个活动要求用户进行身份验证才能使用该设备。
大多数时候这个应用程序运行良好。但是,我在弄清楚如何将第二个活动强制到窗口堆栈的顶部时遇到问题。该代码调用 startActivity 并传入启动第二个活动的意图。问题是当另一个应用程序正在运行时(例如网络浏览器),第二个 Activity 不在顶部。当其他应用程序退出时,第二个活动可见以获取用户的输入。
这是我希望在启动时始终位于顶部的第二个活动的活动定义:
<activity android:name=".Authenticate"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden">
</activity>
据我了解,当调用启动活动时,它将把新活动放在顶部。我有什么遗漏的吗?如何使身份验证活动在启动时位于顶部?
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. The problem is that when another application is running (e.g. a web browser), the second activity is not on top. 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. Is there something that I am missing? How can I make the authentication activity come to the top when it is started?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,据我所知,您不能强迫您的 Activity 始终保持领先。如果某个其他进程(例如 Web 浏览器)在您创建了自己的 Activity 之后创建了一个 Activity,则该进程的 Activity 将拥有焦点,而不是您的。
Well AFAIK, you cannot force your Activity to stay on top all the time. 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.
每当一个新活动启动时,它都会位于堆栈顶部,如果另一个应用程序正在运行,那么它将位于堆栈顶部,如果您希望您的活动位于堆栈顶部,那么您应该停止启动其他应用程序... .有什么我想念的吗,请告诉我..
whenever a new activity starts it is on top of the stack and if another application is running then it will be on the top of the stack and if you want your activity on top of the stack then you should stop other application being launched....Is there something I am missing then let me know..