Android,如何将Task带到前台?
我的问题:
如何在使用以下规则的同时在自己的任务中启动新的活动。
1) 如果该 Activity 已作为另一个任务的根存在(在同一应用程序内),则将该任务置于前台。我不想创建该活动的另一个实例。我只希望它作为根的任务进入前台并显示任务的顶部活动。
注意:它一次只能是一个任务的根,并且只能作为任务的根而存在,而不是其他地方。
2)如果该活动不存在,则在其自己的任务中创建该活动。
为什么我要努力实现这个目标? 我在“活动”的底部创建了四个底部,其行为应类似于选项卡。因此,如果我按第二个“选项卡”,我希望显示与该选项卡关联的活动。但是,如果它已经存在并且位于其自己的任务的底部,那么我希望该任务与当前位于任务顶部的任何活动一起显示。
到目前为止我尝试过什么? 我搜索了 stackOverflow 并没有找到类似的问题。我读了 http://developer.android.com/guide /topics/fundamentals/tasks-and-back-stack.html 和 http://blog.akquinet .de/2010/04/15/android-activites-and-tasks-series-intent-flags/
我想我需要使用 FLAG_ACTIVITY_NEW_TASK和/或亲和力,但不确定。请寻找一只手。
谢谢, 布拉德利4
My question:
How can I launch a new Activity in its own Task while using the following rules.
1) If the Activity already exists as a root of a another Task (within the same application) then bring the Task to the foreground. I don't want another instance of the Activity to be created. I just want the Task that it is the root of to come to the foreground and the top Activity of the Task to be displayed.
Note: it will only be the root of one Task at a time and it will only exist as the root of the Task and nowhere else.
2) If the Activity doesn't exist then create this Activity in its own Task.
Why I'm trying to achieve this?
I created four bottoms at the bottom of my Activities that should behave like tabs. So if I press the second "tab" I want the Activity that is associated with that tab to be displayed. But if it already exist and is on the bottom of its own Task then I would like that Task to be displayed with whatever Activity that is currently on the top of the Task.
What have I tried so far?
I've searched stackOverflow and couldn't find a similar question. I read http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
and http://blog.akquinet.de/2010/04/15/android-activites-and-tasks-series-intent-flags/
I think I need to use either FLAG_ACTIVITY_NEW_TASK and/or affinities but not sure. Looking for a hand please.
Thanks,
Bradley4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我能够为 Android 版本 >= Honeycomb 解决此问题:
您还需要将这些添加到您的清单中:
I was able to solve this for Android version >= Honeycomb:
you also need to add these to your manifest:
您应该使用 FLAG_ACTIVITY_CLEAR_TOP 和 FLAG_ACTIVITY_SINGLE_TOP 在您对 startActivity() 的调用中。
You should use FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP in your call to startActivity().
您可以设置
Activity
的启动模式
(android:launchMode) 在AndroidManifest
中,以便在运行时不会创建自身的新实例,但在未运行时会正常启动。然后,您可以使用 Intent 启动Activity
。You can set the
Activity
'slaunch mode
(android:launchMode) in theAndroidManifest
so that it does not create new instances of itself if it is running, but will launch normally when it is not. Then you can start anActivity
using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT怎么样?
How about FLAG_ACTIVITY_REORDER_TO_FRONT?