Android 将任务置于最前面
我有主要活动+服务。服务正在调用第二个活动。 - 如果 main 位于前台,则一切正常。第二个是在主程序上方打开的。 - 如果我通过“后退”按钮关闭主窗口,则第二个窗口将在桌面上方打开。这很酷。 - 但是当我通过切换到桌面(按“主页”按钮)关闭主程序时,第二个活动将不可见地打开,只有当您切换到应用程序的任务时才能看到它。
如果应用程序在后台运行,您能帮我将任务移至前台吗? 我尝试将第二个活动作为新任务,但这没有帮助。
I have main activity + service. Service is calling second activity.
- If main is in foreground, all is fine. Second is opened above main.
- If I close main by "Back" button, then second is opened above desktop. It's cool.
- BUT when I close main by switching to desktop (press "Home" button), then second activity is opened invisible and you can see it only when you switch to app's task.
Can you help me to move my task to foreground in case if app is in background?
I tried make second activity as new task, but this doesn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将任务中的顶级活动标记为 singleTask,然后向此活动发送任何意图,以便所有任务都将被带到前台,而无需重新创建此活动
Flag top activity in your task as singleTask, than send any intent to this activity so all task will be brought to foreground without recreating this activity
听起来很像我遇到的问题。看看:
http://groups.google.com/group/android-developers/browse_thread /thread/183340108cb847fd
您可以尝试设置任务的亲和力,例如:
在 AndroidManifest.xml 中(同时使活动成为自己的任务,就像您提到的那样)。
如果您不希望其他活动作为单独的任务显示在最近历史记录列表中,
您还可以将: 添加
到清单中的活动中。
Sounds a lot like a problem I had. Look at:
http://groups.google.com/group/android-developers/browse_thread/thread/183340108cb847fd
You can try setting the affinity of your task, like:
in your AndroidManifest.xml (while making the activity its own task, like you mention).
If you don't want the other activity to show up in the recent history list as a separate task,
you can also add:
to the activity in the manifest.
与此问题中提到的问题完全相同。
使用以下代码片段解决了它。
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
;这使活动回到前面。Exact same issue that is mentioned on this Question.
Solved it with following code snippet.
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
; which brings back the activity to front.