简体   繁体   English

按应用程序图标后,在android中启动上次打开的活动

[英]Start last open Activity in android after pressing App icon

I have the following constellation: 我有以下星座:

Press App Icon open Activity A , which checks which activity should open next (Registration or Main Activity B ). 按“应用程序图标”,打开“ 活动A” ,该活动将检查接下来应打开的活动(“注册”或“主要活动B” )。 A is marked as Main Launcher in the xml. 在xml中将A标记为Main Launcher。 Now I go to B . 现在我去B。 Then I have a user action and come to Activity C . 然后,我有一个用户操作,然后进入活动C。 Now I press home. 现在我按回家。 If I chose the app again from background task selector i come back to C . 如果我再次从后台任务选择器中选择了该应用程序,则返回C。 But when I instead press the app icon again,I will start again with A . 但是,当我再次按下应用程序图标时,我将从A重新开始。 Is it possible to handle it in manifest that in this case C should open again or do I have to care it by myself (eg via SharedPreferences?) 是否可以在清单C中重新处理这种情况下进行处理,还是我必须自己照顾一下(例如,通过SharedPreferences?)

This behavior can be controlled in the manifest via android:launchMode . 可以通过android:launchModemanifest控制此行为。

See here: https://developer.android.com/guide/topics/manifest/activity-element.html#lmode and more explanation here: https://developer.android.com/guide/components/tasks-and-back-stack.html 参见此处: https//developer.android.com/guide/topics/manifest/activity-element.html#lmode,以及此处的更多说明: https//developer.android.com/guide/components/tasks-and-back -stack.html

for your scenario, you'd want to keep C and route new intents to the existing instance of it, so this might work: 对于您的方案,您需要保留C并将新的intent路由到它的现有实例,因此这可能有效:

<activity
   android:name="A"
   ...
   android:launchMode="singleTask" />
<activity
   android:name="B"
   ...
   android:launchMode="singleTask" />
<activity
   android:name="C"
   ...
   android:launchMode="singleTask" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 想要在我的应用程序按Launcher Icon后返回上一个Activity - Want to get back to last Activity after pressing Launcher Icon for my app 在按下设备的主页键后,按应用程序图标按下打开最近的活动 - Open recent activity on app icon press , after pressing the home key of device 关闭应用后,在重新启动时启动相同的android最后活动 - Start same android last activity on relaunch after closing the app 按下主页按钮后还如何从Android中的启动活动启动应用程序 - after pressing home button also how to start app from starting activity in android 打开某些固定活动后如何启动上一个开放活动? - How to start last open activity after open some fixed activity? 按下android中的按钮后如何启动一个不同的活动? - How to start a different activity with some delay after pressing a button in android? 在应用程序图标上单击启动屏幕后,如何返回上一次可见的活动:Android - How to come back to last visible activity after splash screen on app icon click: Android 第二个应用的Android启动活动没有第一个应用的图标 - Android start activity of second app having no icon from first app 按下设备的Home键后,如何始终按图标打开当前活动 - How to always open current activity on icon press , after pressing the home key of device 重启应用后,Android显示上一次活动 - Android show last activity after restarting an app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM