简体   繁体   English

如何在其他所有活动之上发起活动?

[英]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.

相关问题 如何使活动再次启动(堆叠在先前的活动之上)? - How to make an activity launch itself again (stacking on top of previous activities)? 框架/工具栏就像所有其他活动之上的单独活动? - Frame/toolbar like separate activity on top of all other activities? 如何清除Android中除前两个活动之外的所有活动? - How can I clear all but the top two activities in Android? 如何删除具有启动模式和活动别名的根活动以外的所有活动? - How to remove all Activities except root activity with launch mode and activity alias? 即使启动了其他活动,我如何才能始终在后台进行一种类型的活动? - How can I always have one type of activity in the background, even if other activities are launched? 如何使一个活动可以显示在其他活动之上? - How to make an activity that can appear above other activities? 如何在应用启动时而非活动创建时设置所有活动的图像视图和文本视图 - How can I set the imageviews and textviews of all my activities at app startup time, not at activity creation 如何获取所有正在运行的活动的列表并选择从暂停到开始状态的任何活动? - How can i get list of all running activities and select any activity from pause to start state? 如何将NavigationDrawer从活动模板添加到其他活动? - How do I add NavigationDrawer from an activity template to other activities? 完成其他活动中的所有先前活动 - Finish all previous activities from other activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM